今日热榜界面简化

仅适用于未登录状态的主界面 自定义背景颜色 卡片颜色 卡片圆角

As of 27.08.2021. See ბოლო ვერსია.

  1. // ==UserScript==
  2. // @name 今日热榜界面简化
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.2.2
  5. // @description 仅适用于未登录状态的主界面 自定义背景颜色 卡片颜色 卡片圆角
  6. // @author Yesaye
  7. // @match *://tophub.today/
  8. // @icon https://www.google.com/s2/favicons?domain=tophub.today
  9. // @grant GM_registerMenuCommand
  10. // @grant GM_unregisterMenuCommand
  11. // @grant GM_openInTab
  12. // @grant GM_getValue
  13. // @grant GM_setValue
  14. // @grant GM_notification
  15. // @run-at document-start
  16.  
  17. // ==/UserScript==
  18.  
  19. (function () {
  20.  
  21. // 页面样式
  22. let style = `#appbar {display: none !important;}#tabbar {display: none !important;}.cq {display: none !important;}.alert {display: none !important;}.eb-fb {display: none !important;}.c-d {padding: 0px !important;}.cc-cd-lb>img {display: none !important;} .cc-cd-lb>span,.cc-cd-sb-st {font-weight:1 !important;}`;
  23. addStyle(style, "setTotalStyle");
  24.  
  25. style = "";
  26. var backgroundColor = GM_getValue("today_BackgroundColor_value")
  27. var cardColor = GM_getValue("today_CardColor_value")
  28. var cardRadius = GM_getValue("today_CardRadius_value");
  29. if (backgroundColor != null) {
  30. style += "body {background-color: " + backgroundColor + " !important;}";
  31. }
  32. if (cardColor != null) {
  33. style += ".cc-cd {background-color: " + cardColor + " !important;}";
  34. }
  35. addStyle(style, "setColorStyle");
  36. style = "";
  37. if (cardRadius != null) {
  38. style += ".cc-cd {border-radius:"+cardRadius+"% !important;}";
  39. }
  40. addStyle(style, "setRadiusStyle");
  41.  
  42. function addStyle(style, clazz) {
  43. let style_Add = document.createElement('style');
  44. style_Add.className = clazz;
  45. if (document.lastChild) {
  46. document.lastChild.appendChild(style_Add).textContent = style;
  47. } else { // 避免网站加载速度太慢的备用措施
  48. let timer1 = setInterval(function () { // 每 10 毫秒检查一下 html 是否已存在
  49. if (document.lastChild) {
  50. clearInterval(timer1); // 取消定时器
  51. document.lastChild.appendChild(style_Add).textContent = style;
  52. }
  53. });
  54. }
  55. }
  56.  
  57. function setStyle(style, clazz) {
  58. // 先删掉原来的
  59. document.querySelectorAll('.'+clazz).forEach((v) => { v.remove() });
  60. addStyle(style, clazz);
  61. }
  62.  
  63.  
  64. // 菜单
  65. var menu_ALL = [
  66. ['today_ChangeColor', '主题', '修改页面主题样式', '']
  67. ], menu_ID = [];
  68. for (let i = 0; i < menu_ALL.length; i++) { // 如果读取到的值为 null 就写入默认值
  69. if (GM_getValue(menu_ALL[i][0]) == null) { GM_setValue(menu_ALL[i][0], menu_ALL[i][3]) };
  70. }
  71. registerMenuCommand();
  72.  
  73. // 注册脚本菜单
  74. function registerMenuCommand() {
  75. if (menu_ID.length > menu_ALL.length) { // 如果菜单ID数组多于菜单数组,说明不是首次添加菜单,需要卸载所有脚本菜单
  76. for (let i = 0; i < menu_ID.length; i++) {
  77. GM_unregisterMenuCommand(menu_ID[i]);
  78. }
  79. }
  80. for (let i = 0; i < menu_ALL.length; i++) { // 循环注册脚本菜单
  81. menu_ALL[i][3] = GM_getValue(menu_ALL[i][0]);
  82. GM_registerMenuCommand(`${menu_ALL[i][1]}`, function () {
  83. menu_setting('checkbox', menu_ALL[i][1], menu_ALL[i][2], [menu_ALL[i + 1], menu_ALL[i + 2], menu_ALL[i + 3], menu_ALL[i + 4]])
  84. });
  85. }
  86. }
  87.  
  88. // 脚本设置
  89. function menu_setting(type, title, tips, menu) {
  90. let _html = `<style class="today_SettingStyle">
  91. .today_SettingRoot {
  92. position: absolute;
  93. top: 50%;
  94. left: 50%;
  95. -webkit-transform: translate(-50%, -50%);
  96. -moz-transform: translate(-50%, -50%);
  97. -ms-transform: translate(-50%, -50%);
  98. -o-transform: translate(-50%, -50%);
  99. transform: translate(-50%, -50%);
  100. width: auto;
  101. min-width: 400px;
  102. max-width: 600px;
  103. height: auto;
  104. min-height: 150px;
  105. max-height: 400px;
  106. color: #535353;
  107. background-color: #fff;
  108. border-radius: 3px;
  109. }
  110.  
  111. .today_SettingBackdrop_1 {
  112. position: fixed;
  113. top: 0;
  114. right: 0;
  115. bottom: 0;
  116. left: 0;
  117. z-index: 203;
  118. display: -webkit-box;
  119. display: -ms-flexbox;
  120. display: flex;
  121. -webkit-box-orient: vertical;
  122. -webkit-box-direction: normal;
  123. -ms-flex-direction: column;
  124. flex-direction: column;
  125. -webkit-box-pack: center;
  126. -ms-flex-pack: center;
  127. justify-content: center;
  128. overflow-x: hidden;
  129. overflow-y: auto;
  130. -webkit-transition: opacity .3s ease-out;
  131. transition: opacity .3s ease-out;
  132. }
  133.  
  134. .today_SettingBackdrop_2 {
  135. position: absolute;
  136. top: 0;
  137. right: 0;
  138. bottom: 0;
  139. left: 0;
  140. z-index: 0;
  141. background-color: rgba(18, 18, 18, 0);
  142. -webkit-transition: background-color .3s ease-out;
  143. transition: background-color .3s ease-out;
  144. }
  145.  
  146. .today_SettingRoot .today_SettingHeader {
  147. padding: 10px 20px;
  148. color: #fff;
  149. font-weight: bold;
  150. background-color: #f0816e;
  151. border-radius: 3px 3px 0 0;
  152. }
  153.  
  154. .today_SettingRoot .today_SettingMain {
  155. padding: 10px 20px;
  156. border-radius: 0 0 3px 3px;
  157. }
  158.  
  159. .today_SettingHeader span {
  160. float: right;
  161. cursor: pointer;
  162. }
  163.  
  164. .today_SettingMain input {
  165. margin: 10px 6px 10px 0;
  166. cursor: pointer;
  167. vertical-align: middle
  168. }
  169.  
  170. .today_SettingMain label {
  171. margin-right: 20px;
  172. user-select: none;
  173. cursor: pointer;
  174. vertical-align: middle
  175. }
  176.  
  177. .today_SettingMain hr {
  178. border: 0.5px solid #f4f4f4;
  179. }
  180.  
  181. [data-theme="dark"] .today_SettingRoot {
  182. color: #adbac7;
  183. background-color: #343A44;
  184. }
  185.  
  186. [data-theme="dark"] .today_SettingHeader {
  187. color: #d0d0d0;
  188. background-color: #2D333B;
  189. }
  190.  
  191. [data-theme="dark"] .today_SettingMain hr {
  192. border: 0.5px solid #2d333b;
  193. }
  194. </style>
  195. <div class="today_SettingBackdrop_1">
  196. <div class="today_SettingBackdrop_2"></div>
  197. <div class="today_SettingRoot">
  198. <div class="today_SettingHeader">${title}
  199. <span class="today_SettingClose" title="点击关闭">
  200. <svg class="Zi Zi--Close Modal-closeIcon" fill="currentColor" viewBox="0 0 24 24" width="24"
  201. height="24">
  202. <path
  203. d="M13.486 12l5.208-5.207a1.048 1.048 0 0 0-.006-1.483 1.046 1.046 0 0 0-1.482-.005L12 10.514 6.793 5.305a1.048 1.048 0 0 0-1.483.005 1.046 1.046 0 0 0-.005 1.483L10.514 12l-5.208 5.207a1.048 1.048 0 0 0 .006 1.483 1.046 1.046 0 0 0 1.482.005L12 13.486l5.207 5.208a1.048 1.048 0 0 0 1.483-.006 1.046 1.046 0 0 0 .005-1.482L13.486 12z"
  204. fill-rule="evenodd">
  205. </path>
  206. </svg>
  207. </span>
  208. </div>
  209. <div class="today_SettingMain">
  210. <div id="today_BackgroundColor_box">
  211. 背景色<input id="pickColor_BackgroundColor" type="color" value="${backgroundColor}">
  212. </div>
  213. <div id="today_CardColor_box">
  214. 卡片色<input id="pickColor_CardColor" type="color" value="${cardColor}">
  215. </div>
  216. <button id="resetColor">重置颜色</button>
  217. <hr/>
  218. <div id="today_CardRadius_box">
  219. 卡片圆角<input type="range" min="0" max="50" value="${cardRadius}" id="today_CardRadius">
  220. </div>
  221. <button id="resetRadius">重置圆角</button>
  222. </div>
  223. </div>
  224. </div>`;
  225.  
  226. document.body.insertAdjacentHTML('beforeend', _html); // 插入网页末尾
  227. setTimeout(function () { // 延迟 100 毫秒,避免太快
  228. // 关闭按钮 点击事件
  229. document.querySelector('.today_SettingClose').onclick = function () { this.parentElement.parentElement.parentElement.remove(); document.querySelector('.today_SettingStyle').remove(); }
  230. // 点击周围空白处 = 点击关闭按钮
  231. document.querySelector('.today_SettingBackdrop_2').onclick = function (event) { if (event.target == this) { document.querySelector('.today_SettingClose').click(); }; }
  232.  
  233. // 选取背景色
  234. document.getElementById("pickColor_BackgroundColor").addEventListener("change", function (e) {
  235. if (e.target.tagName == "INPUT") {
  236. addStyle("body {background-color: " + e.target.value + " !important;}", "setColorStyle");
  237. GM_setValue("today_BackgroundColor_value", e.target.value);
  238. backgroundColor = e.target.value;
  239. }
  240. })
  241. // 选取卡片色
  242. document.getElementById("pickColor_CardColor").addEventListener("change", function (e) {
  243. if (e.target.tagName == "INPUT") {
  244. addStyle(".cc-cd {background-color: " + e.target.value + " !important;}", "setColorStyle");
  245. GM_setValue("today_CardColor_value", e.target.value);
  246. cardColor = e.target.value;
  247. }
  248. })
  249. // 重置背景色和卡片色
  250. document.getElementById("resetColor").onclick = function () {
  251. GM_setValue("today_BackgroundColor_value", null);
  252. GM_setValue("today_CardColor_value", null);
  253. document.getElementById("pickColor_BackgroundColor").value= "#000000";
  254. document.getElementById("pickColor_CardColor").value= "#000000";
  255. document.querySelectorAll('.setColorStyle').forEach((v) => { v.remove() });
  256. }
  257.  
  258. // 设置卡片圆角
  259. document.getElementById("today_CardRadius_box").addEventListener("mousedown", f1, false)
  260. function f1(){
  261. document.getElementById("today_CardRadius_box").addEventListener("mousemove", f2, false)
  262. }
  263. function f2(e) {
  264. cardRadius = document.getElementById("today_CardRadius").value;
  265. GM_setValue("today_CardRadius_value", cardRadius);
  266. setStyle(".cc-cd {border-radius:"+cardRadius+"% !important;}", "setRadiusStyle");
  267. }
  268. document.getElementById("today_CardRadius_box").addEventListener("mouseup", function(e){
  269. document.getElementById("today_CardRadius_box").removeEventListener("mousemove", f2, false);
  270. })
  271. // 重置卡片圆角
  272. document.getElementById("resetRadius").onclick = function () {
  273. GM_setValue("today_CardRadius_value", null);
  274. document.getElementById("today_CardRadius").value= "50%";
  275. document.querySelectorAll('.setRadiusStyle').forEach((v) => { v.remove() });
  276. }
  277. }, 100)
  278. }
  279.  
  280. })();