Skip to content

Instantly share code, notes, and snippets.

@undergroundmonorail
Last active August 29, 2015 14:07
Show Gist options
  • Save undergroundmonorail/3994f1b59be1f9b415b5 to your computer and use it in GitHub Desktop.
Save undergroundmonorail/3994f1b59be1f9b415b5 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name SCP Name Display
// @namespace http://reddit.com/u/undergroundmonorail
// @version 1.4
// @description Show a skip's name in the title of its page
// @match *://www.scp-wiki.net/scp-*
// @match *://scp-wiki.wikidot.com/scp-*
// @match *://www.scp-wiki.net/random:random-scp
// @match *://scp-wiki.wikidot.com/random:random-scp
// @grant GM_xmlhttpRequest
// ==/UserScript==
(function() {
// -------OPTIONS-------
// To enable a feature, put "true;" after the equals sign
// To disable one, put "false;" instead
// Replace the title of the entry (e.g. "SCP-009") with one including the skip's name (e.g. "SCP-009 - Red Ice")
// Does not apply to entries viewed via "Random SCP"
var replaceTitle = true;
// Same as above, but only applies to entries viewed via "Random SCP"
var replaceRandomTitle = true;
// Include the name of the skip in its entry, above "Item #:"
var nameInEntry = false;
// -------END OF OPTIONS-------
var siteUrl = window.location.protocol + '//' + window.location.hostname + '/';
var rand = document.URL.indexOf('random') > -1;
var num = ((/SCP-(\d+)/).exec(document.documentElement.outerHTML))[1];
var series = (num < 1000 ? 1 : Math.floor(num / 1000) + 1);
GM_xmlhttpRequest({
method: "GET",
url: siteUrl + 'scp-series' + (series > 1 ? '-' + series : ''),
onload: function(page) {
var name = new RegExp('SCP-' + num + '</a> - (.*?)</li>').exec(page.responseText)[1];
if ((replaceTitle && !rand) || (replaceRandomTitle && rand)) {
document.getElementById('page-title').innerHTML = 'SCP-' + num + ' - ' + name;
}
if (nameInEntry) {
var content = document.getElementById('page-content');
var numIndex = content.innerHTML.indexOf('<p><strong>Item #:');
content.innerHTML = content.innerHTML.slice(0,numIndex) + '<p><strong>Item Name:</strong> ' + name + content.innerHTML.slice(numIndex);
}
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment