Last active
December 17, 2015 01:59
-
-
Save nt/5532359 to your computer and use it in GitHub Desktop.
Hacke Vison Chrome extension adding it's own tag to all my Amazon urls. Rude.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener('DOMContentLoaded', function () { | |
var ae = '68656c7064757-20'; | |
var an = /(.*\.)?amazon\.(com|[a-z]{2}(\.[a-z]{2})?)$/i; | |
var an2 = /\/gp\/product\/(\w{10})/i; | |
var an3 = /\/exec\/obidos\/tg\/detail\/\-\/(\w{10})/i; | |
var an4 = /\/dp\/(\w{10})/i; | |
var an5 = /\/exec\/obidos\/ASIN\/(\w{10})/i; | |
if (location.hostname.match(an || an2 || an3 || an4 || an5)) { | |
var items = document.evaluate("//a[contains(@href, 'amazon.')]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); | |
mainloop: for (l = null, i = 0; l = items.snapshotItem(i); i++) { | |
if (l.pathname.substr(-16) == ae) { | |
break mainloop | |
} | |
var found = false; | |
var arr = l.pathname.split('/'); | |
for (var n = 0; n < arr.length; n++) { | |
if (arr[n].substr(-3) == '-20') { | |
arr[n] = ae; | |
l.pathname = arr.join('/') + l.search; | |
continue mainloop | |
} | |
} | |
if (!l.search) { | |
l.pathname += '?tag=' + ae; | |
continue mainloop | |
} else { | |
tmp = l.search; | |
if (tmp.substr(0, 1) == '?') { | |
tmp = tmp.substr(1) | |
} | |
var pairs = tmp.split('&'); | |
for (n = 0; n < pairs.length; n++) { | |
var v = pairs[n].split('='); | |
if (v[0] == 'tag') { | |
v[1] = ae; | |
pairs[n] = v.join('='); | |
l.search = '?' + pairs.join('&'); | |
continue mainloop | |
} | |
} | |
l.search += '&tag=' + ae | |
} | |
} | |
} | |
}); | |
var mode; | |
function onExtensionMessage(request) { | |
if (request.enabled) { | |
document.documentElement.setAttribute('hc', mode + request.scheme) | |
} else { | |
document.documentElement.removeAttribute('hc') | |
} | |
} | |
function onEvent(evt) { | |
if (evt.keyCode == 122 && evt.shiftKey) { | |
chrome.extension.sendRequest({ | |
'toggle_global': true | |
}); | |
evt.stopPropagation(); | |
evt.preventDefault(); | |
return false | |
} | |
if (evt.keyCode == 123 && evt.shiftKey) { | |
chrome.extension.sendRequest({ | |
'toggle_site': true | |
}); | |
evt.stopPropagation(); | |
evt.preventDefault(); | |
return false | |
} | |
return true | |
} | |
function init() { | |
if (window == window.top) { | |
mode = 'a' | |
} else { | |
mode = 'b' | |
} | |
chrome.extension.onRequest.addListener(onExtensionMessage); | |
chrome.extension.sendRequest({ | |
'init': true | |
}, onExtensionMessage); | |
document.addEventListener('keydown', onEvent, false) | |
} | |
init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment