Skip to content

Instantly share code, notes, and snippets.

@dannvix
Last active February 12, 2018 05:46
Show Gist options
  • Select an option

  • Save dannvix/d2d5f8e0b7daa2635254 to your computer and use it in GitHub Desktop.

Select an option

Save dannvix/d2d5f8e0b7daa2635254 to your computer and use it in GitHub Desktop.

Revisions

  1. dannvix revised this gist Jul 21, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion PocketWebCustomization.user.js
    Original file line number Diff line number Diff line change
    @@ -98,7 +98,7 @@ var preserveScrollPositionAfterSyncUp = function() {
    ,' var origSyncCallback = queue.syncCallback;'
    ,' var lastScrollY = 0;'
    ,' queue.syncCallback = function() {'
    ,' lastScrollY = window.scrollY;
    ,' lastScrollY = window.scrollY;'
    ,' origSyncCallback.apply(this, arguments);'
    ,' window.scrollTo(window.scrollX, lastScrollY);'
    ,' };'
  2. dannvix revised this gist Jul 21, 2016. 1 changed file with 6 additions and 22 deletions.
    28 changes: 6 additions & 22 deletions PocketWebCustomization.user.js
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    // @namespace http://getpocket.com
    // @author Shao-Chung Chen
    // @license MIT (http://opensource.org/licenses/MIT)
    // @version 1.9
    // @version 1.9.1
    // @include http://getpocket.com/*
    // @include https://getpocket.com/*
    //
    @@ -91,29 +91,14 @@ var hideLiveChatButton = function() {
    };


    var disableItemSynchronization = function() {
    var delaySecs = 1;
    setTimeout(function() {
    // inject script to interact with jQuery
    var script = document.createElement('script');
    script.text = 'jQuery(window).off("focus");';
    document.body.appendChild(script);
    }, delaySecs * 1000/*ms*/);
    };


    var restoreScrollPositionAfterSyncUp = function() {
    // hook `queue.sync` and `queue.syncCallback` via injected script
    var preserveScrollPositionAfterSyncUp = function() {
    // hook and `queue.syncCallback` via injected script
    var script = document.createElement('script');
    script.text = ['(function() {'
    ,' var origSync = queue.sync,'
    ,' origSyncCallback = queue.syncCallback;'
    ,' var origSyncCallback = queue.syncCallback;'
    ,' var lastScrollY = 0;'
    ,' queue.sync = function() {'
    ,' lastScrollY = window.scrollY;'
    ,' origSync.apply(this, arguments);'
    ,' };'
    ,' queue.syncCallback = function() {'
    ,' lastScrollY = window.scrollY;
    ,' origSyncCallback.apply(this, arguments);'
    ,' window.scrollTo(window.scrollX, lastScrollY);'
    ,' };'
    @@ -127,6 +112,5 @@ if (window.location.hostname.toLowerCase().indexOf('getpocket.com') >= 0) {
    window.addEventListener('load', addCustomizationIndicator, false);
    window.addEventListener('load', hideAllShareButtons, false);
    window.addEventListener('load', hideLiveChatButton, false);
    // window.addEventListener('load', disableItemSynchronization, false);
    window.addEventListener('load', restoreScrollPositionAfterSyncUp, false);
    window.addEventListener('load', preserveScrollPositionAfterSyncUp, false);
    }
  3. dannvix revised this gist Jul 14, 2016. 1 changed file with 35 additions and 5 deletions.
    40 changes: 35 additions & 5 deletions PocketWebCustomization.user.js
    Original file line number Diff line number Diff line change
    @@ -4,10 +4,11 @@
    // @namespace http://getpocket.com
    // @author Shao-Chung Chen
    // @license MIT (http://opensource.org/licenses/MIT)
    // @version 1.8
    // @version 1.9
    // @include http://getpocket.com/*
    // @include https://getpocket.com/*
    //
    // @history 1.9 restore scroll position after item synchronization
    // @history 1.8 remove "utm_xxx=yyy" from URL parameters
    // @history 1.7 fix original link parsing
    // @history 1.6 disable automatic item synchronization
    @@ -33,9 +34,12 @@ var switchToOriginalLinks = function() {
    // unbind click event handler to prevent batch selection
    // since we cannot access jQuery here, we use this tricky hack
    var script = document.createElement('script');
    script.text = 'jQuery(".item").off("click");' +
    'jQuery(".item_link").off("click");' +
    'jQuery(".item_content").off("click");';
    script.text = ['(function() {'
    ,' jQuery(".item").off("click");'
    ,' jQuery(".item_link").off("click");'
    ,' jQuery(".item_content").off("click");'
    ,'})();'
    ].join('\n');
    document.body.appendChild(script);
    };

    @@ -71,19 +75,22 @@ var addCustomizationIndicator = function() {
    document.body.appendChild(indicator);
    };


    var hideAllShareButtons = function() {
    var style = document.createElement('style');
    style.textContent = 'li.action_share { display: none; }';
    document.head.appendChild(style);
    };


    var hideLiveChatButton = function() {
    var chatBtn = document.querySelector('#livechat-compact-container');
    if (chatBtn) {
    document.body.removeChild(chatBtn);
    }
    };


    var disableItemSynchronization = function() {
    var delaySecs = 1;
    setTimeout(function() {
    @@ -94,9 +101,32 @@ var disableItemSynchronization = function() {
    }, delaySecs * 1000/*ms*/);
    };


    var restoreScrollPositionAfterSyncUp = function() {
    // hook `queue.sync` and `queue.syncCallback` via injected script
    var script = document.createElement('script');
    script.text = ['(function() {'
    ,' var origSync = queue.sync,'
    ,' origSyncCallback = queue.syncCallback;'
    ,' var lastScrollY = 0;'
    ,' queue.sync = function() {'
    ,' lastScrollY = window.scrollY;'
    ,' origSync.apply(this, arguments);'
    ,' };'
    ,' queue.syncCallback = function() {'
    ,' origSyncCallback.apply(this, arguments);'
    ,' window.scrollTo(window.scrollX, lastScrollY);'
    ,' };'
    ,'})();'
    ].join('\n');
    document.body.appendChild(script);
    };


    if (window.location.hostname.toLowerCase().indexOf('getpocket.com') >= 0) {
    window.addEventListener('load', addCustomizationIndicator, false);
    window.addEventListener('load', hideAllShareButtons, false);
    window.addEventListener('load', hideLiveChatButton, false);
    // window.addEventListener('load', disableItemSynchronization, false);
    }
    window.addEventListener('load', restoreScrollPositionAfterSyncUp, false);
    }
  4. dannvix revised this gist Jul 12, 2016. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions PocketWebCustomization.user.js
    Original file line number Diff line number Diff line change
    @@ -4,10 +4,11 @@
    // @namespace http://getpocket.com
    // @author Shao-Chung Chen
    // @license MIT (http://opensource.org/licenses/MIT)
    // @version 1.7
    // @version 1.8
    // @include http://getpocket.com/*
    // @include https://getpocket.com/*
    //
    // @history 1.8 remove "utm_xxx=yyy" from URL parameters
    // @history 1.7 fix original link parsing
    // @history 1.6 disable automatic item synchronization
    // @history 1.5 hide the live chat button
    @@ -24,7 +25,8 @@ var switchToOriginalLinks = function() {
    var a = item.querySelector('a');
    var originalUrl = item.querySelector('.favicon').getAttribute('data-originalurl');
    var parsedUrl = decodeURIComponent(originalUrl.match(/https?:\/\/getpocket.com\/redirect\?url=(.*)&formCheck=./)[1]);
    a.href = parsedUrl || originalUrl;
    var effectiveUrl = (parsedUrl || originalUrl).replace(/utm_\w+=[^&]+&?/g, "");
    a.href = effectiveUrl;
    item.classList.add('original-link');
    });

  5. dannvix revised this gist Jul 12, 2016. 1 changed file with 7 additions and 6 deletions.
    13 changes: 7 additions & 6 deletions PocketWebCustomization.user.js
    Original file line number Diff line number Diff line change
    @@ -4,10 +4,11 @@
    // @namespace http://getpocket.com
    // @author Shao-Chung Chen
    // @license MIT (http://opensource.org/licenses/MIT)
    // @version 1.6
    // @version 1.7
    // @include http://getpocket.com/*
    // @include https://getpocket.com/*
    //
    // @history 1.7 fix original link parsing
    // @history 1.6 disable automatic item synchronization
    // @history 1.5 hide the live chat button
    // @history 1.4 rename; update for new Pocket Web
    @@ -22,7 +23,7 @@ var switchToOriginalLinks = function() {
    [].forEach.call(allItems, function(item, index) {
    var a = item.querySelector('a');
    var originalUrl = item.querySelector('.favicon').getAttribute('data-originalurl');
    var parsedUrl = decodeURIComponent(originalUrl.match(/https?:\/\/getpocket.com\/redirect\?url=(.*)/)[1]);
    var parsedUrl = decodeURIComponent(originalUrl.match(/https?:\/\/getpocket.com\/redirect\?url=(.*)&formCheck=./)[1]);
    a.href = parsedUrl || originalUrl;
    item.classList.add('original-link');
    });
    @@ -48,7 +49,7 @@ var mutationObserver = new MutationObserver(function(mutations) {
    mutationObserver.observe(target, config);
    switchToOriginalLinks();

    var addOriginalLinkIndicator = function() {
    var addCustomizationIndicator = function() {
    var styles = {
    background: 'hsla(0, 0%, 0%, 0.67)',
    bottom: '10px',
    @@ -92,8 +93,8 @@ var disableItemSynchronization = function() {
    };

    if (window.location.hostname.toLowerCase().indexOf('getpocket.com') >= 0) {
    window.addEventListener('load', addOriginalLinkIndicator, false);
    window.addEventListener('load', addCustomizationIndicator, false);
    window.addEventListener('load', hideAllShareButtons, false);
    window.addEventListener('load', hideLiveChatButton, false);
    window.addEventListener('load', disableItemSynchronization, false);
    }
    // window.addEventListener('load', disableItemSynchronization, false);
    }
  6. dannvix revised this gist Jun 18, 2016. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion PocketWebCustomization.user.js
    Original file line number Diff line number Diff line change
    @@ -4,10 +4,11 @@
    // @namespace http://getpocket.com
    // @author Shao-Chung Chen
    // @license MIT (http://opensource.org/licenses/MIT)
    // @version 1.5
    // @version 1.6
    // @include http://getpocket.com/*
    // @include https://getpocket.com/*
    //
    // @history 1.6 disable automatic item synchronization
    // @history 1.5 hide the live chat button
    // @history 1.4 rename; update for new Pocket Web
    // @history 1.3 efficient patch; hide share buttons
    @@ -80,8 +81,19 @@ var hideLiveChatButton = function() {
    }
    };

    var disableItemSynchronization = function() {
    var delaySecs = 1;
    setTimeout(function() {
    // inject script to interact with jQuery
    var script = document.createElement('script');
    script.text = 'jQuery(window).off("focus");';
    document.body.appendChild(script);
    }, delaySecs * 1000/*ms*/);
    };

    if (window.location.hostname.toLowerCase().indexOf('getpocket.com') >= 0) {
    window.addEventListener('load', addOriginalLinkIndicator, false);
    window.addEventListener('load', hideAllShareButtons, false);
    window.addEventListener('load', hideLiveChatButton, false);
    window.addEventListener('load', disableItemSynchronization, false);
    }
  7. dannvix revised this gist Jun 2, 2016. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions PocketWebCustomization.user.js
    Original file line number Diff line number Diff line change
    @@ -4,10 +4,11 @@
    // @namespace http://getpocket.com
    // @author Shao-Chung Chen
    // @license MIT (http://opensource.org/licenses/MIT)
    // @version 1.4
    // @version 1.5
    // @include http://getpocket.com/*
    // @include https://getpocket.com/*
    //
    // @history 1.5 hide the live chat button
    // @history 1.4 rename; update for new Pocket Web
    // @history 1.3 efficient patch; hide share buttons
    // @history 1.2 unbind click event of items
    @@ -72,7 +73,15 @@ var hideAllShareButtons = function() {
    document.head.appendChild(style);
    };

    var hideLiveChatButton = function() {
    var chatBtn = document.querySelector('#livechat-compact-container');
    if (chatBtn) {
    document.body.removeChild(chatBtn);
    }
    };

    if (window.location.hostname.toLowerCase().indexOf('getpocket.com') >= 0) {
    window.addEventListener('load', addOriginalLinkIndicator, false);
    window.addEventListener('load', hideAllShareButtons, false);
    }
    window.addEventListener('load', hideLiveChatButton, false);
    }
  8. dannvix renamed this gist Apr 14, 2015. 1 changed file with 9 additions and 6 deletions.
    15 changes: 9 additions & 6 deletions PocketOriginalLink.user.js → PocketWebCustomization.user.js
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,14 @@
    // ==UserScript==
    // @name Pocket Original Link
    // @description Use original link by default
    // @name Pocket Web Customized
    // @description Cusotmizations/Simplifications for Pocket Web
    // @namespace http://getpocket.com
    // @author Shao-Chung Chen
    // @license MIT (http://opensource.org/licenses/MIT)
    // @version 1.3
    // @version 1.4
    // @include http://getpocket.com/*
    // @include https://getpocket.com/*
    //
    // @history 1.4 rename; update for new Pocket Web
    // @history 1.3 efficient patch; hide share buttons
    // @history 1.2 unbind click event of items
    // @history 1.1 add indicator
    @@ -27,7 +28,9 @@ var switchToOriginalLinks = function() {
    // unbind click event handler to prevent batch selection
    // since we cannot access jQuery here, we use this tricky hack
    var script = document.createElement('script');
    script.text = 'jQuery(".item").off("click");';
    script.text = 'jQuery(".item").off("click");' +
    'jQuery(".item_link").off("click");' +
    'jQuery(".item_content").off("click");';
    document.body.appendChild(script);
    };

    @@ -56,7 +59,7 @@ var addOriginalLinkIndicator = function() {
    }

    var indicator = document.createElement('div');
    indicator.innerHTML = 'Original Links Enabled'
    indicator.innerHTML = 'Customizations Applied'
    for (var attr in styles) {
    indicator.style[attr] = styles[attr];
    }
    @@ -72,4 +75,4 @@ var hideAllShareButtons = function() {
    if (window.location.hostname.toLowerCase().indexOf('getpocket.com') >= 0) {
    window.addEventListener('load', addOriginalLinkIndicator, false);
    window.addEventListener('load', hideAllShareButtons, false);
    }
    }
  9. dannvix revised this gist Dec 20, 2014. 1 changed file with 24 additions and 15 deletions.
    39 changes: 24 additions & 15 deletions PocketOriginalLink.user.js
    Original file line number Diff line number Diff line change
    @@ -4,31 +4,34 @@
    // @namespace http://getpocket.com
    // @author Shao-Chung Chen
    // @license MIT (http://opensource.org/licenses/MIT)
    // @version 1.2
    // @version 1.3
    // @include http://getpocket.com/*
    // @include https://getpocket.com/*
    //
    // @history 1.3 efficient patch; hide share buttons
    // @history 1.2 unbind click event of items
    // @history 1.1 add indicator
    // @history 1.0 initial commmit
    // ==/UserScript==

    var switchToOriginalLinks = function() {
    var allItems = document.querySelectorAll('.item');
    [].forEach.call(allItems, function(item, index) {
    var a = item.querySelector('a');
    var originalUrl = item.querySelector('.favicon').getAttribute('data-originalurl');
    var parsedUrl = decodeURIComponent(originalUrl.match(/https?:\/\/getpocket.com\/redirect\?url=(.*)/)[1]);
    a.href = parsedUrl || originalUrl;
    });
    var allItems = document.querySelectorAll('.item:not(.original-link)');
    [].forEach.call(allItems, function(item, index) {
    var a = item.querySelector('a');
    var originalUrl = item.querySelector('.favicon').getAttribute('data-originalurl');
    var parsedUrl = decodeURIComponent(originalUrl.match(/https?:\/\/getpocket.com\/redirect\?url=(.*)/)[1]);
    a.href = parsedUrl || originalUrl;
    item.classList.add('original-link');
    });

    // unbind click event handler to prevent batch selection
    // since we cannot access jQuery here, we use this tricky hack
    var script = document.createElement('script');
    script.text = 'jQuery(".item").off("click");';
    document.body.appendChild(script);
    // unbind click event handler to prevent batch selection
    // since we cannot access jQuery here, we use this tricky hack
    var script = document.createElement('script');
    script.text = 'jQuery(".item").off("click");';
    document.body.appendChild(script);
    };


    var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
    var target = document.querySelector('#queue');
    var config = { attributes: true, childList: true, characterData: true };
    @@ -40,7 +43,6 @@ var mutationObserver = new MutationObserver(function(mutations) {
    mutationObserver.observe(target, config);
    switchToOriginalLinks();


    var addOriginalLinkIndicator = function() {
    var styles = {
    background: 'hsla(0, 0%, 0%, 0.67)',
    @@ -61,6 +63,13 @@ var addOriginalLinkIndicator = function() {
    document.body.appendChild(indicator);
    };

    var hideAllShareButtons = function() {
    var style = document.createElement('style');
    style.textContent = 'li.action_share { display: none; }';
    document.head.appendChild(style);
    };

    if (window.location.hostname.toLowerCase().indexOf('getpocket.com') >= 0) {
    window.addEventListener('load', addOriginalLinkIndicator, false);
    }
    window.addEventListener('load', hideAllShareButtons, false);
    }
  10. dannvix revised this gist Dec 13, 2014. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion PocketOriginalLink.user.js
    Original file line number Diff line number Diff line change
    @@ -60,4 +60,7 @@ var addOriginalLinkIndicator = function() {
    }
    document.body.appendChild(indicator);
    };
    window.addEventListener('load', addOriginalLinkIndicator, false);

    if (window.location.hostname.toLowerCase().indexOf('getpocket.com') >= 0) {
    window.addEventListener('load', addOriginalLinkIndicator, false);
    }
  11. dannvix revised this gist Dec 13, 2014. 1 changed file with 8 additions and 4 deletions.
    12 changes: 8 additions & 4 deletions PocketOriginalLink.user.js
    Original file line number Diff line number Diff line change
    @@ -4,10 +4,11 @@
    // @namespace http://getpocket.com
    // @author Shao-Chung Chen
    // @license MIT (http://opensource.org/licenses/MIT)
    // @version 1.1
    // @version 1.2
    // @include http://getpocket.com/*
    // @include https://getpocket.com/*
    //
    // @history 1.2 unbind click event of items
    // @history 1.1 add indicator
    // @history 1.0 initial commmit
    // ==/UserScript==
    @@ -19,10 +20,13 @@ var switchToOriginalLinks = function() {
    var originalUrl = item.querySelector('.favicon').getAttribute('data-originalurl');
    var parsedUrl = decodeURIComponent(originalUrl.match(/https?:\/\/getpocket.com\/redirect\?url=(.*)/)[1]);
    a.href = parsedUrl || originalUrl;

    // unbind click event handler to prevent batch selection
    item.off("click");
    });

    // unbind click event handler to prevent batch selection
    // since we cannot access jQuery here, we use this tricky hack
    var script = document.createElement('script');
    script.text = 'jQuery(".item").off("click");';
    document.body.appendChild(script);
    };

    var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
  12. dannvix revised this gist Dec 13, 2014. 1 changed file with 28 additions and 2 deletions.
    30 changes: 28 additions & 2 deletions PocketOriginalLink.user.js
    Original file line number Diff line number Diff line change
    @@ -4,10 +4,11 @@
    // @namespace http://getpocket.com
    // @author Shao-Chung Chen
    // @license MIT (http://opensource.org/licenses/MIT)
    // @version 1.0
    // @version 1.1
    // @include http://getpocket.com/*
    // @include https://getpocket.com/*
    //
    // @history 1.1 add indicator
    // @history 1.0 initial commmit
    // ==/UserScript==

    @@ -18,6 +19,9 @@ var switchToOriginalLinks = function() {
    var originalUrl = item.querySelector('.favicon').getAttribute('data-originalurl');
    var parsedUrl = decodeURIComponent(originalUrl.match(/https?:\/\/getpocket.com\/redirect\?url=(.*)/)[1]);
    a.href = parsedUrl || originalUrl;

    // unbind click event handler to prevent batch selection
    item.off("click");
    });
    };

    @@ -30,4 +34,26 @@ var mutationObserver = new MutationObserver(function(mutations) {
    });

    mutationObserver.observe(target, config);
    switchToOriginalLinks();
    switchToOriginalLinks();


    var addOriginalLinkIndicator = function() {
    var styles = {
    background: 'hsla(0, 0%, 0%, 0.67)',
    bottom: '10px',
    color: 'white',
    fontSize: '8pt',
    padding: '5px 7px',
    position: 'fixed',
    right: '10px',
    zIndex: '9999',
    }

    var indicator = document.createElement('div');
    indicator.innerHTML = 'Original Links Enabled'
    for (var attr in styles) {
    indicator.style[attr] = styles[attr];
    }
    document.body.appendChild(indicator);
    };
    window.addEventListener('load', addOriginalLinkIndicator, false);
  13. dannvix created this gist Dec 11, 2014.
    33 changes: 33 additions & 0 deletions PocketOriginalLink.user.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    // ==UserScript==
    // @name Pocket Original Link
    // @description Use original link by default
    // @namespace http://getpocket.com
    // @author Shao-Chung Chen
    // @license MIT (http://opensource.org/licenses/MIT)
    // @version 1.0
    // @include http://getpocket.com/*
    // @include https://getpocket.com/*
    //
    // @history 1.0 initial commmit
    // ==/UserScript==

    var switchToOriginalLinks = function() {
    var allItems = document.querySelectorAll('.item');
    [].forEach.call(allItems, function(item, index) {
    var a = item.querySelector('a');
    var originalUrl = item.querySelector('.favicon').getAttribute('data-originalurl');
    var parsedUrl = decodeURIComponent(originalUrl.match(/https?:\/\/getpocket.com\/redirect\?url=(.*)/)[1]);
    a.href = parsedUrl || originalUrl;
    });
    };

    var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
    var target = document.querySelector('#queue');
    var config = { attributes: true, childList: true, characterData: true };

    var mutationObserver = new MutationObserver(function(mutations) {
    switchToOriginalLinks();
    });

    mutationObserver.observe(target, config);
    switchToOriginalLinks();