在网页上记笔记

浅浅记一下笔记。

  1. // ==UserScript==
  2. // @name 在网页上记笔记
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-02-16
  5. // @description 浅浅记一下笔记。
  6. // @author EnrynHsu
  7. // @match https://cn.bing.com/*
  8. // @match https://*/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=bing.com
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13. (function() {
  14. 'use strict';
  15.  
  16. // Your code here...
  17. const editor_pad = document.createElement('div')
  18. document.body.appendChild(editor_pad)
  19. editor_pad.innerHTML = "<button id='hsu_button_edit'>记笔记</button>"
  20.  
  21. document.getElementById('hsu_button_edit').addEventListener('click',() => {
  22. editor_pad.innerHTML = "<label id='hsu_editor_padheader' style='display: block;" +
  23. " margin-bottom: 10px; font-size: 0.8rem;" +
  24. " letter-spacing: 1px;' \"story\">Your Note:</label>\n" +
  25. " <textarea style=' font-size: 0.95rem; padding: 10px;" +
  26. " max-width: 100%; font-family: 新宋体,serif;" +
  27. " line-height: 1.5;" +
  28. " border-radius: 5px;" +
  29. " border: 1px solid #ccc;" +
  30. " box-shadow: 1px 1px 1px #999;" +
  31. " letter-spacing: 0px;' \"story\" name=\"story\" rows=\"5\" cols=\"33\">" +
  32. "" +
  33. "</textarea>"
  34. editor_pad.style.position = "fixed"
  35. editor_pad.style.top = "300px"
  36. editor_pad.style.right = "300px"
  37. editor_pad.style.width = "300px"
  38. editor_pad.style.height = "300px"
  39. editor_pad.style.zIndex = "99999999999999"
  40. editor_pad.id = "hsu_editor_pad"
  41. dragElement(editor_pad)
  42. })
  43. // editor_pad.innerHTML = "<label id='hsu_editor_padheader' style='display: block;" +
  44. // " margin-bottom: 10px; font-size: 0.8rem;" +
  45. // " letter-spacing: 1px;' \"story\">Tell us your story:</label>\n" +
  46. // " <textarea style=' font-size: 0.95rem; padding: 10px;" +
  47. // " max-width: 100%; font-family: 新宋体,serif;" +
  48. // " line-height: 1.5;" +
  49. // " border-radius: 5px;" +
  50. // " border: 1px solid #ccc;" +
  51. // " box-shadow: 1px 1px 1px #999;" +
  52. // " letter-spacing: 0px;' \"story\" name=\"story\" rows=\"5\" cols=\"33\">\n" +
  53. // " It was a dark and stormy night...\n" +
  54. // " </textarea>"
  55. editor_pad.style.position = "fixed"
  56. editor_pad.style.bottom = "0px"
  57. editor_pad.style.right = "10px"
  58. editor_pad.style.width = "300px"
  59. editor_pad.style.height = "300px"
  60. editor_pad.style.zIndex = "9999999999999999"
  61. editor_pad.id = "hsu_editor_pad"
  62.  
  63.  
  64.  
  65.  
  66. function dragElement(element) {
  67. let pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
  68. if (document.getElementById(element.id + "header")) {
  69. // 如果存在,标题是您从中移动 DIV 的位置:
  70. document.getElementById(element.id + "header").onmousedown = dragMouseDown;
  71. } else {
  72. // 否则,从 DIV 内的任何位置移动 DIV:
  73. element.onmousedown = dragMouseDown;
  74. }
  75.  
  76. function dragMouseDown(e) {
  77. e = e || window.event;
  78. e.preventDefault();
  79. // 在启动时获取鼠标光标位置:
  80. pos3 = e.clientX;
  81. pos4 = e.clientY;
  82. document.onmouseup = closeDragElement;
  83. // 每当光标移动时调用一个函数:
  84. document.onmousemove = elementDrag;
  85. }
  86.  
  87. function elementDrag(e) {
  88. e = e || window.event;
  89. e.preventDefault();
  90. // 计算新的光标位置:
  91. pos1 = pos3 - e.clientX;
  92. pos2 = pos4 - e.clientY;
  93. pos3 = e.clientX;
  94. pos4 = e.clientY;
  95. // 设置元素的新位置:
  96. element.style.top = (element.offsetTop - pos2) + "px";
  97. element.style.left = (element.offsetLeft - pos1) + "px";
  98. }
  99.  
  100. function closeDragElement() {
  101. // 释放鼠标按钮时停止移动:
  102. document.onmouseup = null;
  103. document.onmousemove = null;
  104. }
  105. }
  106. })();

QingJ © 2025

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