Greasy Fork is available in English.

common.js

common filter

Ce script ne devrait pas être installé directement. C'est une librairie créée pour d'autres scripts. Elle doit être inclus avec la commande // @require https://update.greatest.deepsurf.us/scripts/463829/1174761/commonjs.js

  1. /**
  2. * 过滤的通用模板
  3. * @param targets 选择对象
  4. * @param forFunction (target) => 遍历选择对象的元素
  5. */
  6. function filterTemplate(targets, forFunction) {
  7. let indexs = [];
  8. targets.each((index, element) => {
  9. if (forFunction($(element))) {
  10. indexs.push(index);
  11. }
  12. });
  13. if (indexs.length == 0) {
  14. return;
  15. }
  16. for (const i of indexs) {
  17. targets[i].remove();
  18. }
  19. }
  20. /**
  21. * 文本模糊匹配的过滤模板
  22. * @param targets 选择对象
  23. * @param textSelector 文本对象的选择器
  24. * @param texts 文本过滤关键词
  25. */
  26. function textFilter(target, textSelector, textKeys) {
  27. let text = target.find(textSelector).text();
  28. for (const textKey of textKeys) {
  29. if (text.indexOf(textKey) != -1) {
  30. return true;
  31. }
  32. }
  33. return false;
  34. }
  35. /**
  36. * 文本精准相等过滤模板
  37. * @param target 选择对象
  38. * @param textSelector 文本对象的选择器
  39. * @param keySet 过滤关键词
  40. */
  41. function keyFilter(target, textSelector, keySet) {
  42. if (null == keySet || 0 == keySet.length) {
  43. return;
  44. }
  45. let title = target.find(textSelector).text();
  46. return keySet.has(title);
  47. }
  48. /**
  49. * 设置,如果第一次失败则开启一个定时任务设置直到成功
  50. * @param selector 位置的文本
  51. * @param func 具体设置的方法
  52. */
  53. function doWithInterval(selector, func) {
  54. let position = $(selector);
  55. if (position.length != 0) {
  56. func(position);
  57. return;
  58. }
  59. let timerTask = setInterval(function () {
  60. position = $(selector);
  61. if (position.length != 0) {
  62. func(position);
  63. clearInterval(timerTask);
  64. }
  65. }, 500);
  66. }