带鱼屏助手

有些网站对超宽屏支持不好,这个插件可以强制将网页宽度设置成1080居中显示,可以勉强用一下。

  1. // ==UserScript==
  2. // @name 带鱼屏助手
  3. // @namespace http://trycatch.xyz/dyp
  4. // @version 0.1
  5. // @description 有些网站对超宽屏支持不好,这个插件可以强制将网页宽度设置成1080居中显示,可以勉强用一下。
  6. // @author Yang
  7. // @include *
  8. // @grant GM_log
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @grant GM_registerMenuCommand
  12. // @grant GM_unregisterMenuCommand
  13. // ==/UserScript==
  14.  
  15. (function () {
  16. 'use strict';
  17.  
  18. const DB_KEY = "HOST_LIST";
  19. let host = window.location.hostname;
  20. let do_cmd_id = GM_registerMenuCommand("适配", on_do);
  21. let undo_cmd_id = GM_registerMenuCommand("取消适配", on_undo);
  22. let do_cmd_show = true;
  23. let undo_cmd_show = true;
  24.  
  25. function show_do_cmd() {
  26. if(do_cmd_show == false) {
  27. do_cmd_id = GM_registerMenuCommand("适配", on_do);
  28. do_cmd_show = true;
  29. }
  30. }
  31.  
  32. function show_undo_cmd() {
  33. if(undo_cmd_show == false) {
  34. undo_cmd_id = GM_registerMenuCommand("取消适配", on_undo);
  35. undo_cmd_show = true;
  36. }
  37. }
  38.  
  39. function hide_do_cmd() {
  40. if(do_cmd_show == true) {
  41. GM_unregisterMenuCommand(do_cmd_id);
  42. do_cmd_show = false;
  43. }
  44. }
  45.  
  46. function hide_undo_cmd() {
  47. if(undo_cmd_show == true) {
  48. GM_unregisterMenuCommand(undo_cmd_id);
  49. undo_cmd_show = false;
  50. }
  51. }
  52.  
  53. function is_host_in_db(host) {
  54. let host_list = GM_getValue(DB_KEY, []);
  55. if (host_list.indexOf(host) == -1) {
  56. return false;
  57. } else {
  58. return true;
  59. }
  60. }
  61.  
  62. function add_host(host) {
  63. if (is_host_in_db(host)) {
  64. return;
  65. }
  66. let host_list = GM_getValue(DB_KEY, []);
  67. host_list.push(host)
  68. GM_setValue(DB_KEY, host_list);
  69. }
  70.  
  71. function remove_host(host) {
  72. if (is_host_in_db(host)) {
  73. let host_list = GM_getValue(DB_KEY, []);
  74. let new_list = host_list.filter(item => item != host)
  75. GM_setValue(DB_KEY, new_list);
  76. }
  77. }
  78.  
  79. function on_do() {
  80. add_host(host);
  81. document.body.style.left = (document.body.clientWidth - 1080) / 2 + "px";
  82. document.body.style.width = "1080px";
  83. document.body.style.position = "relative";
  84. hide_do_cmd();
  85. show_undo_cmd();
  86. };
  87.  
  88. function on_undo() {
  89. remove_host(host);
  90. hide_undo_cmd();
  91. show_do_cmd();
  92. window.location.reload();
  93. };
  94.  
  95. if (is_host_in_db(host)) {
  96. hide_do_cmd();
  97. show_undo_cmd();
  98. on_do();
  99. } else {
  100. hide_undo_cmd();
  101. show_do_cmd();
  102. }
  103. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址