domweigher 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/bin/domweigher +7 -0
- data/domweigher.gemspec +17 -0
- data/lib/domweigher.rb +21 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b63914c55870be838ce509d59cdd6614496ae9e49a78c5dd08c0e22a4c410b01
|
4
|
+
data.tar.gz: b568da83caec37ef2299a3b8a557f95f0f9ab532b241b23fe7c8438e235b11e7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 498bb64e96651144906dbf6c7a9281c1e0d4f9ccbd606cc625ca3533bbfadedfb18237bbe5161765b7ae8fe78ea9619b649992d18c314da9370f9de17b960883
|
7
|
+
data.tar.gz: 80f6380da0ac5c79682bbd9419d6cd5c5817b4fe143e31e0d1c8c557c2e6c08c44fbaf4b88f3db576a6ff59c140969b7dc0f64b4c949138807d10e8e72fb516d
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Victor Maslov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/bin/domweigher
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
mult = Integer((ARGV.shift; ARGV.shift)) if "--mult" == ARGV.first
|
3
|
+
abort "usage:\tdomweigher [--mult <n>] <file.htm>" unless 1 == ARGV.size
|
4
|
+
abort "the argument should be a file" unless File.exist? ARGV.first
|
5
|
+
abort "the argument should be a file" unless File.file? ARGV.first
|
6
|
+
require_relative "../lib/domweigher"
|
7
|
+
puts DOMWeigher ARGF.read, *mult
|
data/domweigher.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "domweigher"
|
3
|
+
spec.version = "0.0.0"
|
4
|
+
spec.summary = "tool to find the heavy DOM nodes"
|
5
|
+
|
6
|
+
spec.author = "Victor Maslov aka Nakilon"
|
7
|
+
spec.email = "nakilon@gmail.com"
|
8
|
+
spec.license = "MIT"
|
9
|
+
spec.metadata = {"source_code_uri" => "https://github.com/nakilon/domweigher"}
|
10
|
+
|
11
|
+
spec.add_dependency "nokogiri"
|
12
|
+
|
13
|
+
spec.files = %w{ LICENSE domweigher.gemspec lib/domweigher.rb
|
14
|
+
bin/domweigher }
|
15
|
+
spec.executables = %w{ domweigher }
|
16
|
+
spec.bindir = "bin"
|
17
|
+
end
|
data/lib/domweigher.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
def DOMWeigher string, mult = 10
|
2
|
+
require "nokogiri"
|
3
|
+
root = ::Nokogiri.HTML(string).root
|
4
|
+
all_size = root.to_s.size
|
5
|
+
all = [[0, root]]
|
6
|
+
loop do
|
7
|
+
(d, n) = all.select{ |__,_| _.is_a? ::Nokogiri::XML::Element }.max_by{ |__,_| _.to_s.size }
|
8
|
+
break unless d
|
9
|
+
break if n.to_s.size * mult < all_size
|
10
|
+
all[all.index([d, n]), 1] = [
|
11
|
+
[n.to_s.size, "%#{d}s%s" % [nil, "#{n.name}#{".#{n[:class].split.join ?.}" if n[:class]}"]],
|
12
|
+
*(n.elements.map{ |_| [d+1, _] } unless %w{ svg }.include? n.name),
|
13
|
+
]
|
14
|
+
end
|
15
|
+
require "io/console"
|
16
|
+
y, x = ::IO.console.winsize
|
17
|
+
max = all.select{ |__,_| _.is_a? ::String }.map(&:first).max.to_s.size
|
18
|
+
all.map do |a, b|
|
19
|
+
"%#{max}s %-#{x-max-1}s" % [a, b] if b.is_a? ::String
|
20
|
+
end.compact
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: domweigher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Victor Maslov aka Nakilon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-05-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description:
|
28
|
+
email: nakilon@gmail.com
|
29
|
+
executables:
|
30
|
+
- domweigher
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- LICENSE
|
35
|
+
- bin/domweigher
|
36
|
+
- domweigher.gemspec
|
37
|
+
- lib/domweigher.rb
|
38
|
+
homepage:
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata:
|
42
|
+
source_code_uri: https://github.com/nakilon/domweigher
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubygems_version: 3.3.27
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: tool to find the heavy DOM nodes
|
62
|
+
test_files: []
|