Greasy Fork 支持简体中文。

Fullscreen Button

A simple float button for entering fullscreen.

  1. // ==UserScript==
  2. // @name Fullscreen Button
  3. // @name:zh-CN 全屏按钮
  4. // @match *://*/*
  5. // @version 0.2
  6. // @description A simple float button for entering fullscreen.
  7. // @description:zh-CN 一个简单的浮动按钮用于全屏显示网页。
  8. // @noframes
  9. // @license CC0
  10. // @namespace https://greasyfork.org/users/123506
  11. // ==/UserScript==
  12. 'use strict';
  13.  
  14. // Check if the fullscreen button already exists
  15. var btn = document.getElementById("b0n");
  16.  
  17. // If it doesn't exist, create it
  18. if (!btn) {
  19. document.body.insertAdjacentHTML("afterbegin", '<div id="b0n" style="background-color: rgb(209, 209, 209);position: fixed;display: flex;opacity: 0.66;margin: 1em;z-index: 2147483647" ><svg width="24" height="24"><path d="M7,14L5,14v5h5v-2L7,17v-3zM5,10h2L7,7h3L10,5L5,5v5zM17,17h-3v2h5v-5h-2v3zM14,5v2h3v3h2L19,5h-5z"/></svg></div>');
  20. btn = document.getElementById("b0n");
  21. }
  22.  
  23. var reF = document.documentElement.requestFullscreen || document.documentElement.webkitRequestFullscreen;
  24.  
  25. var action = function () {
  26. reF.call(document.documentElement);
  27. }
  28.  
  29. btn.onclick = action;
  30.  
  31. // Variables for long press and touch events
  32. var longPressTimer;
  33. var isTouching = false;
  34. var touchOffsetX, touchOffsetY;
  35.  
  36. // Add touch event listeners
  37. btn.addEventListener("touchstart", function (e) {
  38. isTouching = true;
  39. var touch = e.touches[0];
  40. touchOffsetX = touch.clientX - btn.getBoundingClientRect().left;
  41. touchOffsetY = touch.clientY - btn.getBoundingClientRect().top;
  42.  
  43. // Set a long press timer for 500 milliseconds
  44. longPressTimer = setTimeout(function () {
  45. btn.style.cursor = "grabbing";
  46. }, 500);
  47. });
  48.  
  49. btn.addEventListener("touchmove", function (e) {
  50. if (!isTouching) return;
  51. var touch = e.touches[0];
  52. var x = touch.clientX - touchOffsetX;
  53. var y = touch.clientY - touchOffsetY;
  54. btn.style.left = x + "px";
  55. btn.style.top = y + "px";
  56. e.preventDefault(); // Prevent page scrolling while dragging
  57. });
  58.  
  59. btn.addEventListener("touchend", function () {
  60. isTouching = false;
  61. clearTimeout(longPressTimer);
  62. btn.style.cursor = "grab";
  63. });