zenyBoost

个人辅助

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

  1. // ==UserScript==
  2. // @name zenyBoost
  3. // @namespace http://tampermonkey.net/
  4. // @namespace https://coderschool.cn
  5. // @version 0.1
  6. // @description 个人辅助
  7. // @author yuexiaojun
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=huaban.com
  9. // @include *
  10. // @grant unsafeWindow
  11. // @grant GM_setClipboard
  12. // @grant GM_download
  13. // @grant GM_addStyle
  14. // @grant GM_notification
  15. // @require https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
  16. // @require https://cdn.bootcdn.net/ajax/libs/clipboard.js/2.0.6/clipboard.min.js
  17. // ==/UserScript==
  18.  
  19.  
  20. //字符串增强
  21. String.prototype.format = function(...args) {
  22. if (args.length == 1 && typeof args[0] == 'object') {
  23. let k = '', v = ''
  24. return this.replace(/{[A-Za-z]+}/g, (it, i) => {
  25. k = it.slice(1, -1)
  26. v = args[0][k]
  27. return typeof v != 'undefined' ? v : '';
  28. })
  29. }
  30. return this.replace(/{(\d+)}/g, (it, i) => {
  31. return typeof args[i] != 'undefined' ? args[i] : '';
  32. });
  33. };
  34. var log = console.log;
  35.  
  36.  
  37. //打开新窗口
  38. function openNewWindowWithText(s) {
  39. // 打开一个新的窗口
  40. const newWindow = window.open('', '_blank', 'width=400,height=300');
  41.  
  42. // 检查窗口是否成功打开
  43. if (newWindow) {
  44. // 向窗口的文档写入内容
  45. newWindow.document.write(s);
  46. newWindow.document.title = 'My New Window';
  47.  
  48. // 关闭文档流,确保所有资源被正确加载
  49. newWindow.document.close();
  50. return newWindow;
  51. } else {
  52. // 如果窗口没有成功打开(可能由于浏览器阻止弹窗)
  53. alert('Window could not be opened. Please check your popup settings.');
  54. }
  55. }