Greasy Fork 支持简体中文。

Ruler

Inspired by https://www.v2ex.com/t/878358

  1. // ==UserScript==
  2. // @name Ruler
  3. // @namespace Violentmonkey Scripts
  4. // @include *
  5. // @grant none
  6. // @version 1.0
  7. // @license MIT
  8. // @author fuckduanluan
  9. // @description Inspired by https://www.v2ex.com/t/878358
  10. // ==/UserScript==
  11.  
  12.  
  13. window.addEventListener('load', () => {
  14. const dec = decodeURIComponent,
  15. enc = encodeURIComponent,
  16. decode = function decode(s) {
  17. return s.replace(/(%[0-9A-Z]{2})+/g, dec);
  18. };
  19.  
  20. function setCookie(key, value, _temp) {
  21. let _ref = _temp === void 0 ? {} : _temp,
  22. expires = _ref.expires,
  23. domain = _ref.domain,
  24. secure = _ref.secure,
  25. _ref$path = _ref.path,
  26. path = _ref$path === void 0 ? '/' : _ref$path;
  27.  
  28. if (typeof value !== 'string') {
  29.  
  30. value = String(value);
  31. }
  32.  
  33.  
  34. key = enc(key.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, dec));
  35.  
  36.  
  37. value = enc(value.replace(/%(23|24|26|2B|5E|60|7C)/g, dec).replace(/[\\]/g, escape));
  38. let text = key + "=" + value;
  39. text += "; path=" + path.split(';')[0];
  40.  
  41. typeof expires === 'number' && (expires = new Date(Date.now() + expires * 36e5));
  42.  
  43.  
  44. expires instanceof Date && (text += "; expires=" + expires.toUTCString());
  45. typeof domain === 'string' && (text += "; domain=" + domain.split(';')[0]);
  46. secure && (text += '; secure');
  47. return document.cookie = text;
  48. }
  49.  
  50. function getCookie(key) {
  51. const cookies = document.cookie ? document.cookie.split('; ') : [],
  52. rst = [];
  53.  
  54. for (let i = 0, len = cookies.length; i < len; ++i) {
  55. let part = cookies[i].split('='),
  56. name = decode(part[0]),
  57. value = decode(part.slice(1).join('='));
  58. name === key && rst.push(value);
  59. }
  60.  
  61. return rst.length ? rst.length === 1 ? rst[0] : rst : null;
  62. }
  63. if (getCookie('hasBanner')) return;
  64. const banner = document.createElement('div');
  65. banner.style.cssText = `
  66. color: #eee;
  67. font-size: 24px;
  68. text-shadow: 0 3px 3px #666;
  69. line-height: 22px;
  70. padding: 8px;
  71. font-family: "Microsoft Yahei";
  72. text-align: center;
  73. cursor: pointer;
  74. position: fixed;
  75. top: 0px;
  76. left: 0px;
  77. right: 0px;
  78. z-index: 9999;
  79. background: linear-gradient(-45deg, #0057b7 25%, #ffd700 0, #ffd700 50%, #0057b7 0, #0057b7 75%, #ffd700 0);
  80. background-size: 100px 100px;
  81. box-shadow: 0 3px 10px #aaa;
  82. `;
  83. banner.textContent = '我们终将在没有黑暗的地方相见';
  84. banner.addEventListener('click', function() {
  85. this.style.display = 'none';
  86. setCookie('hasBanner', 1, { expires: 24 * 7 });
  87. });
  88. document.body.appendChild(banner);
  89. });