Facebook
From xd, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 208
  1. // ==UserScript==
  2. // @name         Youtube old design
  3. // @namespace    4c5725cd7d4b94b6f1784e759d5a43fbdd917971
  4. // @version      0.1
  5. // @description  Activates the old YT design without messing with your other settings
  6. // @author       /u/AyrA_ch
  7. // @match        https://www.youtube.com/*
  8. // @match        http://www.youtube.com/*
  9. // @match        https://youtube.com/*
  10. // @match        http://youtube.com/*
  11. // @grant        none
  12. // @run-at       document-start
  13. // ==/UserScript==
  14.  
  15. (function () {
  16.     var getDesignCookie = function (cookie) {
  17.         //Find existing preferences
  18.         var prefs = cookie.split("; ").filter(function (v) {
  19.                 return v.indexOf("PREF=") === 0;
  20.             })[0];
  21.         //No preferences, return new ones with design setting
  22.         if (!prefs) {
  23.             console.log("prefs not set in cookie");
  24.             return "PREF=f6=8";
  25.         }
  26.         //Process all settings
  27.         var entries = prefs.substr(5).split('&');
  28.         var set = false;
  29.         for (var i = 0; i < entries.length; i++) {
  30.             if (entries[i].indexOf("f6=") === 0) {
  31.                 set = true;
  32.                 //Set the old design flag
  33.                 var value = +entries[i].substr(3);
  34.                 if ((value & 8) === 0) {
  35.                     console.log("Activating old design and reloading...");
  36.                     entries[i] = "f6=" + (value | 8);
  37.                     window.setTimeout(location.reload.bind(location,true),100);
  38.                 }
  39.                 else{
  40.                     console.log("Old design already active. Doing nothing");
  41.                 }
  42.             }
  43.         }
  44.         //Design flag setting doesn't exists. Adding it instead
  45.         if (!set) {
  46.             console.log("Activating old design and reloading...");
  47.             entries.push("f6=8");
  48.             window.setTimeout(location.reload.bind(location,true),100);
  49.         }
  50.         //Build cookie
  51.         return "PREF=" + entries.join('&');
  52.     };
  53.     //Update cookie
  54.     document.cookie = getDesignCookie(document.cookie) + ";domain=.youtube.com;path=/";
  55. })();
  56.  
  57. /*
  58. LICENSE:
  59. This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
  60. The full license text can be found here: http://creativecommons.org/licenses/by-nc-sa/4.0/
  61. The link has an easy to understand version of the license and the full license text.
  62.  
  63. DISCLAIMER:
  64. THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  65. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  66. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
  67. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  68. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  69. OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  70. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  71. OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  72. THE POSSIBILITY OF SUCH DAMAGE.
  73. */