Last active
February 20, 2019 12:25
-
-
Save Rudokhvist/22e3e945e292fd925a0752dbf0d93e98 to your computer and use it in GitHub Desktop.
Beta version of "Redirect Removed Steam ID to steamdb" of dynamic pages
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== | |
// @name Redirect Removed Steam ID to steamdb | |
// @namespace https://greasyfork.org/en/users/2205-ryzhehvost | |
// @description Redirects links to removed AppID's on steampowered.com to steamdb.info | |
// @description:en Redirects links to removed AppID's on steampowered.com to steamdb.info | |
// @locale en-US | |
// @include * | |
// @version 1.3 | |
// @grant none | |
// ==/UserScript== | |
function addanchors(element) { | |
try { | |
var links = element.getElementsByTagName('a'); | |
for (var i=links.length-1; i>=0; i--) { | |
if (links[i].hasAttribute("href")) { | |
if (links[i].getAttribute("href").includes("steampowered")) { | |
if (!links[i].getAttribute("href").includes("#")){ | |
links[i].setAttribute("href",links[i].getAttribute("href").replace(/(http.{0,1}:\/\/store\.steampowered\.com\/)(.*)\/(\d+)(.*)/,"$1$2\/$3$4#$2$3")); | |
} | |
} | |
} | |
} | |
return null; | |
} catch (e) { | |
console.log("Redirect Removed Steam ID to steamdb error"); | |
return null; | |
} | |
} | |
+function () { | |
var res; | |
if (res=window.location.href.match(/http.{0,1}:\/\/store\.steampowered\.com\/#(\D+)(\d+)/)) { | |
window.location = "https:\/\/steamdb.info\/"+res[1]+"\/"+res[2]; | |
} else if (res=window.location.href.match(/(http.{0,1}:\/\/store\.steampowered\.com\/.+)#(\D+)(\d+)/)){ | |
window.history.replaceState(null, null, res[1]); | |
} | |
addanchors(document); | |
var mutationObserver = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
mutation.addedNodes.forEach( function(currentValue, currentIndex, listObj) { | |
if (currentValue.nodeType == Node.ELEMENT_NODE) { | |
addanchors(currentValue); | |
} | |
}); | |
}); | |
}); | |
mutationObserver.observe(document.documentElement, { | |
childList: true, | |
subtree: true | |
}); | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment