Last active
December 23, 2017 09:13
-
-
Save patrickroberts/32a8379c4a2cfd74d4485407c7c8326b to your computer and use it in GitHub Desktop.
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 Automated Permalink | |
// @namespace http://tampermonkey.net/ | |
// @version 2.0 | |
// @description automatically synchronizes permalink to fusion | |
// @author Patrick Roberts | |
// @match http://pokemon.alexonsager.net/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var image = document.getElementById('pk_img'); | |
window.addEventListener('popstate', function () { | |
var match = location.pathname.match(/\/(\d+)\/(\d+)/); | |
pokego(match[1], match[2]); | |
}); | |
function updateHistory() { | |
var prev = location.pathname; | |
var next = image.src.replace(/.*(\d+)\/\1\.(\d+).*/, '/$2/$1'); | |
if (prev === '/') { | |
history.replaceState(null, document.title, next); | |
} else if (prev !== next) { | |
history.pushState(null, document.title, next); | |
} | |
} | |
image.addEventListener('load', updateHistory); | |
updateHistory(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment