Last active
September 14, 2016 07:26
-
-
Save Dither/3038297 to your computer and use it in GitHub Desktop.
AutoPatchWork Mod support script for google video search
This file contains 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
// ==UserScript== | |
// @include http://www.google.*/search*&tbm=vid* | |
// @include https://www.google.*/search*&tbm=vid* | |
// @include https://encrypted.google.com/search*&tbm=vid* | |
// @description AutoPatchWork Mod 1.9.6+ support script for google video search | |
// ==/UserScript== | |
var index = 1, scripts = ''; | |
function handleNewPageLoad(event) { | |
var doc = event.detail.htmlDoc, | |
nodes = doc.querySelectorAll('img[id^="vidthumb"]'), | |
scriptNodes = doc.querySelectorAll('script'); | |
scripts = ''; | |
index += nodes.length+1; | |
for (var i = 0; i < scriptNodes.length; i++) | |
if ((new RegExp("\\w\\('vidthumb\\d+'", 'gi')).test(scriptNodes[i].innerText)) { | |
scripts += scriptNodes[i].innerText; | |
} | |
for (var oldid, newid, x, i = 0; i < nodes.length; i++, index++) { | |
newid = "vidthumb" + index; | |
oldid = nodes[i].id; | |
if (scripts.length) scripts = scripts.replace("'" + oldid + "'", "'" + newid + "'"); | |
nodes[i].id = newid; | |
} | |
} | |
function handleNewPageLoaded(event) { | |
var x = document.createElement('script'); | |
x.type = 'text/javascript'; | |
x.text = scripts; | |
(document.getElementsByTagName('head')[0] || document.documentElement).appendChild(x); | |
setTimeout( (function(){ x.parentNode.removeChild(x); })(x), 1000); | |
} | |
document.addEventListener('AutoPatchWork.load', handleNewPageLoad, false); | |
document.addEventListener('AutoPatchWork.pageloaded', handleNewPageLoaded, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment