Skip to content

Instantly share code, notes, and snippets.

@patrickroberts
Last active December 23, 2017 09:13
Show Gist options
  • Save patrickroberts/32a8379c4a2cfd74d4485407c7c8326b to your computer and use it in GitHub Desktop.
Save patrickroberts/32a8379c4a2cfd74d4485407c7c8326b to your computer and use it in GitHub Desktop.
// ==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