Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save iki/03af4eda558efd56d038520889afb56a to your computer and use it in GitHub Desktop.

Select an option

Save iki/03af4eda558efd56d038520889afb56a to your computer and use it in GitHub Desktop.

Revisions

  1. iki revised this gist May 10, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Medium: remove location hash.user.js
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    // @description Remove location hash from medium
    // @include https://medium.com/*
    // @include https://uxdesign.cc/*
    // @version 2
    // @version 1
    // @grant none
    // ==/UserScript==

    @@ -28,7 +28,7 @@ function removeLocationHashAndStop(event) {
    removeLocationHash(event);
    }
    function removeLocationHashAndScheduleNext(event) {
    event.scheduleMs = removeLocationHash(event) ? event.scheduleMinMs || 500 : Math.min((event.scheduleMs || event.scheduleMinMs || 1000) * 2, event.scheduleMaxMs || 60000);
    event.scheduleMs = removeLocationHash(event) ? event.scheduleMinMs || 500 : Math.min((event.scheduleMs || event.scheduleMinMs || 500) * 2, event.scheduleMaxMs || 60000);
    event.type = 'schedule';
    console.log('medium: remove hash: schedule after ' + event.scheduleMs + 'ms');
    setTimeout(function() { removeLocationHashAndScheduleNext(event); }, event.scheduleMs);
  2. iki revised this gist May 10, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Medium: remove location hash.user.js
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    // @description Remove location hash from medium
    // @include https://medium.com/*
    // @include https://uxdesign.cc/*
    // @version 1
    // @version 2
    // @grant none
    // ==/UserScript==

  3. iki revised this gist May 10, 2016. 1 changed file with 33 additions and 14 deletions.
    47 changes: 33 additions & 14 deletions Medium: remove location hash.user.js
    Original file line number Diff line number Diff line change
    @@ -2,23 +2,42 @@
    // @name Medium: remove location hash
    // @namespace http://efcl.info/
    // @description Remove location hash from medium
    // @include https://medium.com/*#*
    // @include https://uxdesign.cc/*#*
    // @include https://medium.com/*
    // @include https://uxdesign.cc/*
    // @version 1
    // @grant none
    // ==/UserScript==

    function removeLocationHash(){
    var noHashURL = window.location.href.replace(/#.*$/, '');
    window.history.replaceState('', document.title, noHashURL);
    // TamperMonkey does not work well with hash '#' in @include urls:
    // https://forum.tampermonkey.net/viewtopic.php?p=3094#p3094

    function removeLocationHash(event) {
    var components = window.location.href.split('#');
    if (components.length > 1) {
    var base = components[0];
    var hash = components.slice(1).join('#');
    if (hash) {
    console.log('medium: remove hash' + (event && event.type ? ' on ' + event.type : '') + ' #' + hash, arguments);
    window.history.replaceState('', document.title, base);
    }
    return hash;
    }
    }
    window.addEventListener("popstate", function(event){
    removeLocationHash();
    });
    window.addEventListener("hashchange", function(event){
    function removeLocationHashAndStop(event) {
    event.preventDefault();
    removeLocationHash();
    });
    window.addEventListener("load", function(){
    removeLocationHash();
    });
    removeLocationHash(event);
    }
    function removeLocationHashAndScheduleNext(event) {
    event.scheduleMs = removeLocationHash(event) ? event.scheduleMinMs || 500 : Math.min((event.scheduleMs || event.scheduleMinMs || 1000) * 2, event.scheduleMaxMs || 60000);
    event.type = 'schedule';
    console.log('medium: remove hash: schedule after ' + event.scheduleMs + 'ms');
    setTimeout(function() { removeLocationHashAndScheduleNext(event); }, event.scheduleMs);
    }
    function registerRemoveLocationHash() {
    console.log('medium: remove hash: register');
    window.addEventListener('popstate', removeLocationHash);
    window.addEventListener('hashchange', removeLocationHashAndStop);
    window.addEventListener('load', removeLocationHash);
    removeLocationHashAndScheduleNext({type: 'userscript load'});
    }
    registerRemoveLocationHash();
  4. iki revised this gist May 10, 2016. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Medium: remove location hash.user.js
    Original file line number Diff line number Diff line change
    @@ -3,13 +3,14 @@
    // @namespace http://efcl.info/
    // @description Remove location hash from medium
    // @include https://medium.com/*#*
    // @include https://uxdesign.cc/*#*
    // @version 1
    // @grant none
    // ==/UserScript==

    function removeLocationHash(){
    var noHashURL = window.location.href.replace(/#.*$/, '');
    window.history.replaceState('', document.title, noHashURL)
    window.history.replaceState('', document.title, noHashURL);
    }
    window.addEventListener("popstate", function(event){
    removeLocationHash();
  5. @azu azu created this gist Dec 2, 2015.
    23 changes: 23 additions & 0 deletions Medium: remove location hash.user.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    // ==UserScript==
    // @name Medium: remove location hash
    // @namespace http://efcl.info/
    // @description Remove location hash from medium
    // @include https://medium.com/*#*
    // @version 1
    // @grant none
    // ==/UserScript==

    function removeLocationHash(){
    var noHashURL = window.location.href.replace(/#.*$/, '');
    window.history.replaceState('', document.title, noHashURL)
    }
    window.addEventListener("popstate", function(event){
    removeLocationHash();
    });
    window.addEventListener("hashchange", function(event){
    event.preventDefault();
    removeLocationHash();
    });
    window.addEventListener("load", function(){
    removeLocationHash();
    });