locatine 0.01309 → 0.01439

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36abed5fc9bb50605d737f8f56be664970461ec9
4
- data.tar.gz: 3c5b291cf577d416c2396643425d1129c9957b50
3
+ metadata.gz: 77f63cceefd7594a340e9295b71d7ef491e60ebe
4
+ data.tar.gz: 61cdf5270323f799eec652caa3f528b4491c53f0
5
5
  SHA512:
6
- metadata.gz: a8e84bd41e4c91bc7ad2dfcffd9c1ca92791aa48a3f658b4a21ad73d61215d6b3afd7b7baeeed69b9d45ee1dd0cafca876f9abecc4540b8ffd9ad30d2d448299
7
- data.tar.gz: 8415caf49216b65470b0668c9f98c470c5140982a3328750a8f68bc9d348b496c4b667058efe852ba18f78b65d7c02934716ba4ea9c262d4b88c3994657fa78d
6
+ metadata.gz: 2d7c8bc6e6d829f11be85a9c9e783f521c1cbe18febcee3d073417d7bdc729dc8e840849c88c70610049d9998c52f43e2d949f2b83b5187b9fb59bdf6420810d
7
+ data.tar.gz: 42bd7eec1492d5495ff35e661513fbd2e1add8dd3d6f084e334ffc9119ea646c1f8d2f7f96b817c013fde0b87fec0b62cd787a063b1b8e97b79ddf4aee16f42a
@@ -61,7 +61,7 @@ async function getSelected(value){
61
61
  const tagName = value.tagName;
62
62
  const array = Array.prototype.slice.call( document.getElementsByTagName(tagName) );
63
63
  const index = array.indexOf(value);
64
- if (document.locatine_selected != value) {
64
+ if ((document.locatine_selected != value) && (String(tagName) != "")) {
65
65
  document.locatine_selected = value;
66
66
  await set_value("locatine_confirm", "selected");
67
67
  magic_div.setAttribute("tag", tagName);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "Locatine app",
3
- "version": "0.01309",
3
+ "version": "0.01439",
4
4
  "description": "Messaging from browser to main app",
5
5
  "devtools_page": "devtools.html",
6
6
  "permissions": ["activeTab", "storage", "contextMenus", "tabs"],
@@ -1,56 +1,62 @@
1
1
  module Locatine
2
2
  ##
3
- # Generating locatine json info from element itself
3
+ # Collecting data of element and making it dynamic
4
4
  module DataGenerate
5
5
  private
6
6
 
7
- def get_dynamic_attributes(element, vars)
8
- attrs = []
9
- get_attributes(element).each do |hash|
10
- if vars[hash['name'].to_sym]
11
- hash['value'].gsub!(vars[hash['name'].to_sym], "\#{#{hash['name']}}")
12
- end
13
- attrs.push hash
14
- end
15
- attrs
7
+ def real_text_of(element)
8
+ element.text == element.inner_html ? element.text : ''
9
+ end
10
+
11
+ def mesure(element)
12
+ xy = element.location
13
+ wh = element.size
14
+ return xy.x, xy.y, wh.width, wh.height
16
15
  end
17
16
 
18
17
  def get_dynamic_tag(element, vars)
19
18
  tag = element.tag_name
20
19
  tag = "\#{tag}" if vars[:tag] == tag
21
- { 'name' => 'tag', 'value' => tag, 'type' => 'tag' }
22
- end
23
-
24
- def real_text_of(element)
25
- element.text == element.inner_html ? element.text : ''
20
+ push_hash('tag', tag, 'tag')
26
21
  end
27
22
 
28
23
  def get_dynamic_text(element, vars)
29
24
  attrs = []
30
- real_text_of(element).split(' ').each do |word|
31
- final_word = if !vars[:text].to_s.strip.empty?
32
- word.gsub(vars[:text].to_s, "\#{text}")
33
- else
34
- word
35
- end
36
- attrs.push('name' => 'text', 'value' => final_word, 'type' => 'text')
25
+ real_text_of(element).split(/['" ]/).each do |word|
26
+ final = if !vars[:text].to_s.strip.empty?
27
+ word.gsub(vars[:text].to_s, "\#{text}")
28
+ else
29
+ word
30
+ end
31
+ attrs.push push_hash('text', final, 'text') unless final.empty?
37
32
  end
38
33
  attrs
39
34
  end
40
35
 
41
- ##
42
- # Generating array of hashes representing data of the element
43
- def get_element_info(element, vars, depth)
44
- attrs = get_dynamic_attributes(element, vars)
45
- attrs.push get_dynamic_tag(element, vars)
46
- attrs += get_dynamic_text(element, vars)
47
- attrs += get_dynamic_css(element, vars) if depth.to_i.zero?
48
- attrs
36
+ def process_dimension(name, value, vars)
37
+ s_name = name.to_s
38
+ value = value.to_s.gsub(vars[name], "\#{#{s_name}}") if vars[name]
39
+ value
40
+ end
41
+
42
+ def processed_dimensions(element, vars)
43
+ x, y, width, height = mesure(element)
44
+ x = process_dimension(:x, x, vars)
45
+ y = process_dimension(:y, y, vars)
46
+ width = process_dimension(:width, width, vars)
47
+ height = process_dimension(:height, height, vars)
48
+ return x, y, width, height
49
+ end
50
+
51
+ def get_dimensions(element, vars)
52
+ resolution = window_size
53
+ x, y, w, h = processed_dimensions(element, vars)
54
+ push_hash(resolution, "#{x}*#{y}*#{w}*#{h}", 'dimensions')
49
55
  end
50
56
 
51
57
  def hash_by_style(style, value, vars)
52
58
  value.gsub!(vars[style.to_sym], "\#{#{style}}") if vars[style.to_sym]
53
- { 'name' => style, 'value' => value, 'type' => 'css' }
59
+ push_hash(style, value, 'css')
54
60
  end
55
61
 
56
62
  def get_raw_css(element)
@@ -73,30 +79,6 @@ module Locatine
73
79
  attrs
74
80
  end
75
81
 
76
- ##
77
- # Generating data for group of elements
78
- def generate_data(result, vars)
79
- family = {}
80
- result.each do |item|
81
- family = get_commons(get_family_info(item, vars), family)
82
- end
83
- family
84
- end
85
-
86
- ##
87
- # Getting element\\parents information
88
- def get_family_info(element, vars)
89
- i = 0
90
- attributes = {}
91
- while i != @depth
92
- attributes[i.to_s] = get_element_info(element, vars, i)
93
- i += 1
94
- element = element.parent
95
- i = @depth unless element.exists?
96
- end
97
- attributes
98
- end
99
-
100
82
  ##
101
83
  # Collecting attributes of the element
102
84
  def get_attributes(element)
@@ -105,9 +87,9 @@ module Locatine
105
87
  attributes.each_pair do |name, value|
106
88
  next if name.to_s == 'locatineclass'
107
89
 
108
- value.split(' ').uniq.each do |part|
90
+ value.split(/['" ]/).uniq.each do |part|
109
91
  array.push('name' => name.to_s, 'type' => 'attribute',
110
- 'value' => part)
92
+ 'value' => part) unless part.empty?
111
93
  end
112
94
  end
113
95
  array
@@ -0,0 +1,53 @@
1
+ module Locatine
2
+ ##
3
+ # Logic of collecting data of the element
4
+ module DataLogic
5
+ private
6
+
7
+ def get_dynamic_attributes(element, vars)
8
+ attrs = []
9
+ get_attributes(element).each do |hash|
10
+ if vars[hash['name'].to_sym]
11
+ hash['value'].gsub!(vars[hash['name'].to_sym], "\#{#{hash['name']}}")
12
+ end
13
+ attrs.push hash
14
+ end
15
+ attrs
16
+ end
17
+
18
+ ##
19
+ # Generating array of hashes representing data of the element
20
+ def get_element_info(element, vars, depth)
21
+ attrs = get_dynamic_attributes(element, vars)
22
+ attrs.push get_dynamic_tag(element, vars)
23
+ attrs += get_dynamic_text(element, vars)
24
+ attrs += get_dynamic_css(element, vars) if depth.to_i.zero? && visual?
25
+ attrs.push get_dimensions(element, vars) if depth.to_i.zero? && visual?
26
+ attrs
27
+ end
28
+
29
+ ##
30
+ # Generating data for group of elements
31
+ def generate_data(result, vars)
32
+ family = {}
33
+ result.each do |item|
34
+ family = get_commons(get_family_info(item, vars), family)
35
+ end
36
+ family
37
+ end
38
+
39
+ ##
40
+ # Getting element\\parents information
41
+ def get_family_info(element, vars)
42
+ i = 0
43
+ attributes = {}
44
+ while i != @depth
45
+ attributes[i.to_s] = get_element_info(element, vars, i)
46
+ i += 1
47
+ element = element.parent
48
+ i = @depth unless element.exists?
49
+ end
50
+ attributes
51
+ end
52
+ end
53
+ end
@@ -18,7 +18,7 @@ module Locatine
18
18
 
19
19
  def similar_enough(data, attributes)
20
20
  (same_entries(data['0'], attributes, '0').length * 100 /
21
- data['0'].length) > @tolerance
21
+ data['0'].length) >= @tolerance
22
22
  end
23
23
 
24
24
  def suggest_by_all(all, data, vars, name, scope)
@@ -38,10 +38,58 @@ module Locatine
38
38
  all += one_option_array(hash, vars, depth).to_a
39
39
  end
40
40
  end
41
- all += full_find_by_css(data, vars)
41
+ all += full_find_by_css(data, vars) if visual?
42
+ all += find_by_dimensions(data, vars) if visual?
42
43
  all
43
44
  end
44
45
 
46
+ def min_max_by_size(middle, size)
47
+ min = middle - (size.to_i * (100 + @tolerance)) / 200
48
+ max = middle + (size.to_i * (100 + @tolerance)) / 200
49
+ return min, max
50
+ end
51
+
52
+ def middle(sizes)
53
+ x = sizes[0].to_i + (sizes[2].to_i / 2)
54
+ y = sizes[1].to_i + (sizes[3].to_i / 2)
55
+ return x, y
56
+ end
57
+
58
+ def dimension_search_field(sizes)
59
+ x, y = middle(sizes)
60
+ x_min, x_max = min_max_by_size(x, sizes[2])
61
+ y_min, y_max = min_max_by_size(y, sizes[3])
62
+ return x_min, x_max, y_min, y_max
63
+ end
64
+
65
+ def retrieve_mesures(data)
66
+ size = window_size
67
+ dimensions = data['0'].map do |i|
68
+ i if (i['type'] == 'dimensions') && (i['name'] == size)
69
+ end
70
+ dimensions.compact
71
+ end
72
+
73
+ def sizez_from_dimensions(dimensions, vars)
74
+ result = []
75
+ dimensions.first['value'].split('*').each do |value|
76
+ result.push(process_string(value, vars))
77
+ end
78
+ result
79
+ end
80
+
81
+ def find_by_dimensions(data, vars)
82
+ dimensions = retrieve_mesures(data)
83
+ if !dimensions.empty?
84
+ sizes = sizez_from_dimensions(dimensions, vars)
85
+ xmi, xma, ymi, yma = dimension_search_field(sizes)
86
+ script = File.read("#{HOME}/large_scripts/dimensions.js")
87
+ engine.execute_script(script, xmi, xma, ymi, yma).compact
88
+ else
89
+ []
90
+ end
91
+ end
92
+
45
93
  def one_option_array(hash, vars, depth)
46
94
  case hash['type']
47
95
  when 'tag'
@@ -23,6 +23,22 @@ module Locatine
23
23
  "[not(@id = 'locatine_magic_div')]"
24
24
  end
25
25
 
26
+ def push_hash(name, value, type)
27
+ { 'name' => name,
28
+ 'value' => value,
29
+ 'type' => type }
30
+ end
31
+
32
+ def window_size
33
+ b_w = engine.execute_script('return window.innerWidth')
34
+ b_h = engine.execute_script('return window.innerHeight')
35
+ "#{b_w}x#{b_h}"
36
+ end
37
+
38
+ def visual?
39
+ @visual_search
40
+ end
41
+
26
42
  def right_browser
27
43
  Watir::Browser.new(:chrome, switches: ["--load-extension=#{HOME}/app"])
28
44
  end
@@ -0,0 +1,17 @@
1
+ function walk(xmi, xma, ymi, yma){
2
+ let x;
3
+ let y;
4
+ let array =[];
5
+ let one;
6
+ for (x = xmi; x <= xma; x++) {
7
+ for (y = ymi; y <= yma; y++) {
8
+ one = document.elementFromPoint(x, y);
9
+ if ((one != document.documentElement) && (one != document.body)){
10
+ array.push(document.elementFromPoint(x, y));
11
+ }
12
+ }
13
+ }
14
+ return [...new Set(array)];
15
+ }
16
+
17
+ return walk(parseInt(arguments[0]), parseInt(arguments[1]), parseInt(arguments[2]), parseInt(arguments[3]))
@@ -32,7 +32,8 @@ module Locatine
32
32
  learn: ENV['LEARN'].nil? ? false : true,
33
33
  stability_limit: 10,
34
34
  scope: 'Default',
35
- tolerance: 33)
35
+ tolerance: 33,
36
+ visual_search: false)
36
37
  import_browser browser
37
38
  import_file(json)
38
39
  @depth = depth
@@ -40,6 +41,7 @@ module Locatine
40
41
  @stability_limit = stability_limit
41
42
  @scope = scope
42
43
  @tolerance = tolerance
44
+ @visual_search = visual_search
43
45
  end
44
46
 
45
47
  ##
@@ -9,6 +9,7 @@ require 'locatine/public'
9
9
  require 'locatine/helpers'
10
10
  require 'locatine/file_work'
11
11
  require 'locatine/highlight'
12
+ require 'locatine/data_logic'
12
13
  require 'locatine/find_logic'
13
14
  require 'locatine/find_by_css'
14
15
  require 'locatine/dialog_logic'
@@ -29,6 +30,7 @@ module Locatine
29
30
  include Locatine::Public
30
31
  include Locatine::Helpers
31
32
  include Locatine::FileWork
33
+ include Locatine::DataLogic
32
34
  include Locatine::FindLogic
33
35
  include Locatine::Highlight
34
36
  include Locatine::FindByCss
@@ -45,7 +47,8 @@ module Locatine
45
47
  :learn,
46
48
  :stability_limit,
47
49
  :scope,
48
- :tolerance
50
+ :tolerance,
51
+ :visual_search
49
52
  attr_reader :json,
50
53
  :browser
51
54
  end
@@ -1,6 +1,6 @@
1
1
  module Locatine
2
2
  # constants here...
3
- VERSION = '0.01309'.freeze
3
+ VERSION = '0.01439'.freeze
4
4
  NAME = 'locatine'.freeze
5
5
  HOME = if File.readable?("#{Dir.pwd}/lib/#{Locatine::NAME}")
6
6
  "#{Dir.pwd}/lib/#{Locatine::NAME}"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locatine
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.01309'
4
+ version: '0.01439'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergei Seleznev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-18 00:00:00.000000000 Z
11
+ date: 2019-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -125,6 +125,7 @@ files:
125
125
  - lib/locatine/app/popup.html
126
126
  - lib/locatine/app/popup.js
127
127
  - lib/locatine/data_generate.rb
128
+ - lib/locatine/data_logic.rb
128
129
  - lib/locatine/dialog_actions.rb
129
130
  - lib/locatine/dialog_logic.rb
130
131
  - lib/locatine/file_work.rb
@@ -136,6 +137,7 @@ files:
136
137
  - lib/locatine/helpers.rb
137
138
  - lib/locatine/highlight.rb
138
139
  - lib/locatine/large_scripts/css.js
140
+ - lib/locatine/large_scripts/dimensions.js
139
141
  - lib/locatine/merge.rb
140
142
  - lib/locatine/public.rb
141
143
  - lib/locatine/search.rb