Change Notion.so NP

Display a small panel to let you change the language back to avoid NP styling for every pages in notion.so

  1. // ==UserScript==
  2. // @name Change Notion.so NP
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Display a small panel to let you change the language back to avoid NP styling for every pages in notion.so
  6. // @author Felix Zhong
  7. // @match https://www.notion.so/*
  8. // @grant none
  9. // @run-at document-end
  10.  
  11. // ==/UserScript==
  12.  
  13.  
  14. var currentPath = '';
  15. var inited = false;
  16. var switherId = 'lang-switcher';
  17. var availableLangs = ['en','zh-CN','jp']; // Change this if you want a different language.
  18.  
  19. debugger
  20.  
  21.  
  22. function run() {
  23.  
  24. function setLang(lang) {
  25. document.getElementsByTagName("html")[0].setAttribute("lang", lang);
  26. var path = window.location.pathname;
  27. langs[path] = lang;
  28.  
  29. var panel = document.getElementById(switherId);
  30. if (!panel) return;
  31.  
  32. var items = Array.from(panel.children)
  33.  
  34. items.forEach(function(item){
  35. item.style.background = 'transparent';
  36.  
  37. if( item.innerHTML === lang) {
  38. item.style.background = '#ccc';
  39. }
  40.  
  41. })
  42. }
  43.  
  44. function createPanel() {
  45. var parent = document.getElementsByClassName('notion-topbar')[0];
  46. if (!parent) return;
  47.  
  48.  
  49. var panel = document.createElement("div");
  50. panel.id = switherId;
  51. panel.style.background = '#eee';
  52. panel.style.position = 'absolute';
  53. panel.style.right = '300px';
  54. panel.style.padding= '0.2em 0';
  55. panel.style.borderRadius = '0 0 3px 3px';
  56.  
  57.  
  58. availableLangs.forEach(function(lang){
  59. var item = document.createElement("span");
  60.  
  61. item.innerHTML = lang;
  62. item.style.margin= '0.2em 0.2em';
  63. item.style.padding ='0.1em 0.4em';
  64. item.style.cursor = 'pointer';
  65. item.style.borderRadius = '3px';
  66.  
  67. item.addEventListener('click', function(event){
  68. setLang(event.target.innerHTML)
  69. saveLangs();
  70. })
  71. panel.appendChild(item)
  72. })
  73.  
  74. parent.appendChild(panel);
  75. inited = true;
  76. }
  77.  
  78. function saveLangs() {
  79. localStorage.setItem('customlangs',JSON.stringify(langs) );
  80. }
  81.  
  82.  
  83. var defaultLang = 'en'
  84. var langs = JSON.parse(localStorage.getItem('customlangs')) || {};
  85. var path = window.location.pathname;
  86. var currentLang = langs[path] || defaultLang;
  87.  
  88. if (!inited) {
  89. createPanel();
  90. }
  91. setLang(currentLang);
  92.  
  93. }
  94.  
  95.  
  96. // create an observer instance
  97. var observer = new MutationObserver(function() {
  98. var path = window.location.pathname;
  99. if (currentPath !== path || !inited) {
  100. currentPath = path;
  101. setTimeout(run, 0)
  102. }
  103. });
  104.  
  105. var config = { characterData: true, attributes: false, childList: true, subtree: true };
  106. var mutgt = document.body;
  107. observer.observe(mutgt, config);

QingJ © 2025

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