Skip to content

Instantly share code, notes, and snippets.

@holocronweaver
Created February 2, 2017 00:44
Show Gist options
  • Save holocronweaver/2cea980159399a5d88514c6ee921b822 to your computer and use it in GitHub Desktop.
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.
// ==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