My_General_Utils

Utils I use for other user scripts.

当前为 2020-06-04 提交的版本,查看 最新版本

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

  1. //My_General_Utils.js
  2.  
  3. //Takes strings of html elements and appendeds it to the selector
  4. function createElements(elements, selector) {
  5. log("createElements Enter", true);
  6. //append element to selector
  7. $(selector).append(elements);
  8. }
  9.  
  10. //waits for a jQuery element to exist then runs callback function
  11. //syntax waitForElement(jQuery selector, function onec element exists, timout in milliseconds)
  12. function waitForElement(selector, callback, ms) {
  13. if(ms == null){
  14. var ms = 100;
  15. }
  16. log("waitForElement Enter", true);
  17. if ($(selector).length) {
  18. callback(selector);
  19. } else {
  20. setTimeout(function () {
  21. waitForElement(selector, callback);
  22. }, ms);
  23. }
  24. }
  25.  
  26. //Feed class string for html elemnt, returns array of all matching elements
  27. function arryElements(element) {
  28. //log("arryElements Enter", true);
  29. //Create an array of all (...) settings buttons
  30. var elemCount = $(element).length;
  31. var elemArr = new Array(elemCount);
  32. elemArr = $(element).each($).toArray();
  33.  
  34. return elemArr;
  35. }
  36.  
  37. // Returns a promise which resolves after x amount of ms. Allows pausing on a line.
  38. function sleep(ms) {
  39. // A promise is returned. When used in an async function with the await keyword, will wait the x amount of milliseconds to resolve and then continue
  40. return new Promise(resolve => setTimeout(resolve, ms));
  41. }