Get me Old Youtube

Sets a Cookie which loads the old Youtube layout (as long as available)

当前为 2017-11-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Get me Old Youtube
  3. // @namespace https://www.youtube.com/
  4. // @version 1.2.2
  5. // @description Sets a Cookie which loads the old Youtube layout (as long as available)
  6. // @copyright Okaïdo53
  7. // @author Okaïdo53
  8. // @compatible firefox
  9. // @compatible chrome
  10. // @compatible opera
  11. // @compatible Safari
  12. // @icon https://www.youtube.com/yts/img/yt_1200-vfl4C3T0K.png
  13. // @match *://www.youtube.com/*
  14. // @exclude *://www.youtube.com/tv*
  15. // @exclude *://www.youtube.com/embed/*
  16. // @exclude *://www.youtube.com/live_chat*
  17. // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
  18. // @resource https://gist.github.com/Okaido53/4eccfc0b4bbe57e4cc510a973e5d9142
  19. // @run-at document-start
  20. // @homepageURL
  21. // @grant none
  22. // @grant unsafeWindow
  23. // @grant GM_getValue
  24. // @grant GM_setValue
  25. // @grant GM_addStyle
  26. // @grant GM_getResourceText
  27. // @grant GM_xmlhttpRequest
  28. // @noframes
  29. // @license GPL v3
  30. // ==/UserScript==
  31.  
  32. (function() {
  33. 'use strict';
  34.  
  35. function start() {
  36. var cookie = getPref(),
  37. pref = "f6=8";
  38. if(cookie === "fIsAlreadySet") {
  39. return;
  40. } else if(cookie !== "noPref"){
  41. for(var i = 0; i < cookie.length; ++i) {
  42. pref = pref + "&" + cookie[i].key + "=" + cookie[i].value;
  43. }
  44. }
  45. changePref(pref);
  46. }
  47. function changePref(values) {
  48. var d = new Date();
  49. d.setTime(d.getTime() + (100*24*60*60*1000));
  50. var expires = "expires="+ d.toUTCString();
  51. document.cookie = "PREF=" + values + ";" + expires + ";domain=.youtube.com;hostonly=false;path=/";
  52. location.reload();
  53. }
  54.  
  55. function getPref() {
  56. var cookie = document.cookie,
  57. splitC = cookie.split(";");
  58. for(var i = 0; i < splitC.length; ++i) {
  59. if(splitC[i].trim().indexOf("PREF") === 0) {
  60. if(splitC[i].trim().indexOf("f6=8") > -1) {
  61. return "fIsAlreadySet";
  62. }
  63. var c = [],
  64. splitValues = splitC[i].substring(5).split("&");
  65. for(var k = 0; k < splitValues.length; ++k) {
  66. var splitV = splitValues[k].split("=");
  67. if(splitV[0] !== "f6") {
  68. var kv = {};
  69. kv.key = splitV[0];
  70. kv.value = splitV[1];
  71. c.push(kv);
  72. }
  73. }
  74. return c;
  75. }
  76. }
  77. return "noPref";
  78. }
  79. start();
  80. })();