forked from nicolethenerd/mckayla
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontentscript.js
More file actions
77 lines (67 loc) · 2.36 KB
/
contentscript.js
File metadata and controls
77 lines (67 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Constants
var THRESHOLD = .2
,MCKAYLA_IMG_URL = chrome.extension.getURL('mckayla.png')
,ORIG_WIDTH = 1024
,ORIG_HEIGHT = 1483
,WIDTH_RATIO = 0.3
,HEIGHT_RATIO = 0.8
// McKayla generator should be separated into it's own script
var McKayla = {
generate: function(src) {
var
width
,height
,src_img = {
zIndex: $(src).css('z-index')
,width: $(src).width()
,height: $(src).height()
// ,width: $(src).outerWidth()
// ,height: $(src).outerHeight()
// ,right: $(src).offset().left + $(src).outerWidth()
// ,bottom: $(src).offset().top + $(src).outerHeight()
}
src_img.right = $(src).offset().left + src_img.width
src_img.bottom = $(src).offset().top + src_img.height
console.log(src_img)
// Calculate McKayla dimensions
if(src_img.height <= src_img.width) {
height = HEIGHT_RATIO * src_img.height
width = ORIG_WIDTH * height/ORIG_HEIGHT
} else {
width = WIDTH_RATIO * src_img.width
height = ORIG_HEIGHT * width/ORIG_WIDTH
}
var img = document.createElement('img')
img.width = width
img.height = height
img.src = MCKAYLA_IMG_URL
img.style.position = 'absolute'
img.style.left = (src_img.right - width) + 'px'
img.style.top = (src_img.bottom - height) + 'px'
img.style['z-index'] = 1 + (src_img.zIndex !== 'auto' ? src_img.zIndex : 0)
return img;
}
,add: function(src_img, parent) {
var img = this.generate(src_img)
$(img).click(function(e) {
e.preventDefault()
$(this).hide(250)
})
parent = parent || document.body
parent.appendChild(img)
}
}
jQuery(document).ready(function($) {
console.log('Overlaying McKayla...:')
$('img:visible').each(function() {
if (Math.random() <= THRESHOLD
&& $(this) != undefined
&& $(this).attr('src') != undefined
&& $(this).attr('src') != MCKAYLA_IMG_URL
&& $(this).height() >= 50) {
console.log($(this).attr('src'))
// Create instance of McKayla object and add to document body
McKayla.add(this)
}
})
})