-
Notifications
You must be signed in to change notification settings - Fork 3
/
contentscript.js
56 lines (53 loc) · 2.42 KB
/
contentscript.js
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
//Main
window.onload = function(){
//Add stylesheet
var link = document.createElement('link');
link.href = chrome.extension.getURL('failsafe.css');
//chrome-extension://<extension id>/main.css
link.rel = 'stylesheet';
document.documentElement.insertBefore(link);
$(".visuallyhidden pre").each(function() {
new FailSafe($(this));
});
if (document.location.href.indexOf("showImgInfo=true") > -1){
iQInfo.showIqInfo();
}
// showIqInfo();
console.log("FailsafeViewer Chrome Extension initialized");
}
// requires:
// jQuery
// adds the
var iQInfo = (function(){
var showIqInfoEnabled = false
function iQInfoElement(info_string){
return $('<div class="iq-info-div">'+info_string+'</div>').get(0);
}
function showIqInfo(){
if (showIqInfoEnabled) return;
showIqInfoEnabled = true;
$(".iq-img").each(function(index,elm){
var infoString = '';
infoString += "desktop: <a href=\""+$(elm).data("src-desktop")+"\" target=\"_blank\">"+ getURLParameter($(elm).data("src-desktop"), "wid") + "px</a>, ";
infoString += "desktop-2X: <a href=\""+$(elm).data("src-desktop-highres")+"\" target=\"_blank\">"+ getURLParameter($(elm).data("src-desktop-highres"), "wid")+ "px</a><br>";
infoString += "tablet: <a href=\""+$(elm).data("src-tablet")+"\" target=\"_blank\">"+ getURLParameter($(elm).data("src-tablet"), "wid") + "px</a>, ";
infoString += "tablet-2X: <a href=\""+$(elm).data("src-tablet-highres")+"\" target=\"_blank\">"+ getURLParameter($(elm).data("src-tablet-highres"), "wid")+ "px</a><br>";
infoString += "phone: <a href=\""+$(elm).data("src-phone")+"\" target=\"_blank\">"+ getURLParameter($(elm).data("src-phone"), "wid") + "px</a>, ";
infoString += "phone-2X: <a href=\""+$(elm).data("src-phone-highres")+"\" target=\"_blank\">"+ getURLParameter($(elm).data("src-phone-highres"), "wid")+ "px</a>";
var newElement = iQInfoElement(infoString);
$(elm).after(newElement);
$(newElement).draggable();
})
}
function getURLParameter(string, name) {
return decodeURI(
(RegExp(name + '=' + '(.+?)(&|$)').exec(string)||[,null])[1]
);
}
return api = {
showIqInfoEnabled: {
get: function(){return showIqInfoEnabled}
},
showIqInfo: function(){showIqInfo()}
}
})()