[F2] Reset Page Title

Press F2 to reset the tab title

  1. // ==UserScript==
  2. // @name [F2] Reset Page Title
  3. // @name:zh-CN [F2] 重设页面标题
  4. // @description Press F2 to reset the tab title
  5. // @description:zh-CN 按F2重新设置标签页标题
  6.  
  7. // @author Moshel
  8. // @namespace https://hzy.pw
  9. // @supportURL https://github.com/h2y/link-fix
  10. // @license GPL-3.0
  11.  
  12. // @version 1.0.0
  13. // @match http://*/*
  14. // @match https://*/*
  15. // @grant none
  16. // @run-at document-body
  17. // @require https://cdn.staticfile.org/keymaster/1.6.1/keymaster.min.js
  18. // ==/UserScript==
  19.  
  20. (function() {
  21. 'use strict';
  22.  
  23. let defaultTitle = document.title;
  24. let title = sessionStorage.getItem('title_by_userscript');
  25. let intervalID = null;
  26. if (title) {
  27. startInterval(title);
  28. }
  29.  
  30. function startInterval(newTitle) {
  31. title = newTitle;
  32. sessionStorage.setItem('title_by_userscript', newTitle);
  33. document.title = newTitle;
  34. if (!intervalID) {
  35. intervalID = setInterval(() => {
  36. document.title = title;
  37. }, 6666);
  38. }
  39. }
  40.  
  41. key("f2", _ => {
  42. let newTitle = prompt('请为页面设置一个标题', title ? title : document.title);
  43. if (newTitle) {
  44. startInterval(newTitle);
  45. } else {
  46. clearInterval(intervalID);
  47. intervalID = null;
  48. document.title = defaultTitle;
  49. }
  50. });
  51. })();