GMLibrary

GMLibary

目前为 2022-12-10 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/456410/1127029/GMLibrary.js

  1. // ==UserScript==
  2. // @name GMLibrary
  3. // @namespace https://greasyfork.org/users/28298
  4. // @version 1.0
  5. // @description GMLibary
  6. // @author Jerry
  7. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  8. // @grant GM_setClipboard
  9. // @grant GM_download
  10. // @grant GM_addStyle
  11. // @grant GM_notification
  12. // @noframes
  13. // @license GNU GPLv3
  14. // ==/UserScript==
  15.  
  16. // match violentmonkey supports * anywhere in url
  17. // GM_notification requires macOS to turn on notification for browser
  18. // https://violentmonkey.github.io/api/gm/
  19. // https://www.tampermonkey.net/documentation.php?ext=dhdg
  20. function addbutton(text,func,top,left,width,height) {
  21. //top, left, [width[, height]] in px
  22. // e.g., width 100px, height 25px
  23. // https://stackoverflow.com/a/1535421/2292993
  24. if (window.top != window.self) {
  25. return;
  26. } //don't run on frames or iframes
  27.  
  28. let btn = document.createElement("button");
  29. btn.innerHTML = text;
  30. document.body.appendChild(btn);
  31. btn.addEventListener("click", func);
  32.  
  33. btn.style.cssText = "border-radius: 5px; border:1px solid black; background-color:#D3D3D3; color:black";
  34. btn.style.position = 'absolute';
  35. btn.style.top = top+'px';
  36. btn.style.left = left+'px';
  37. if (width !== undefined) {btn.style.width = width+'px';}
  38. if (height !== undefined) {btn.style.height = height+'px';}
  39. console.log("top: " + top + 'px' + " left: " + left + 'px');
  40. }
  41.  
  42. // // must call with await in async function; otherwise not working
  43. // function sleep(ms) {
  44. // setTimeout(()=>{console.log("Sleeping...");},3000);
  45. // return new Promise(resolve => setTimeout(resolve, ms));
  46. // }
  47. function sleep(millis) {
  48. var date = new Date();
  49. var curDate = null;
  50. do { curDate = new Date(); }
  51. while(curDate-date < millis);
  52. }