Created
February 2, 2017 00:44
-
-
Save holocronweaver/2cea980159399a5d88514c6ee921b822 to your computer and use it in GitHub Desktop.
A Greasemonkey/Tampermonkey script for defaulting Wookieepedia to Legacy instead of Disney Canon.
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 Wookieepedia Default to Legacy | |
// @namespace https://holocronweaver.com/ | |
// @version 0.1 | |
// @description Default to Legacy instead of Disney Canon. | |
// @author holocronweaver | |
// @match http://starwars.wikia.com/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Check if this page has Canon/Legacy duality and find Legacy URL. | |
var canontabLegendsFields = document.evaluate( | |
"//table[@id='canontab']//td[@id='canontab-legends']//a", | |
document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); | |
// Avoid infinite loop. | |
var legendsNotInUrl = window.location.pathname.search(/Legends$/i) == -1; | |
// If previous page was Legends, do nothing since user wanted to see the Canon page. | |
var prevPageIsNotLegends = document.referrer.search(/Legends$/i) == -1; | |
if (canontabLegendsFields.snapshotLength > 0 && legendsNotInUrl && prevPageIsNotLegends) | |
{ | |
var a = canontabLegendsFields.snapshotItem(0); | |
window.location = a.href; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment