FBase Lib

Base library

目前为 2023-03-22 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/461948/1164976/FBase%20Lib.js

  1. // ==UserScript==
  2. // @name FBase Lib
  3. // @description Base library
  4. // @version 0.0.1
  5. // ==/UserScript==
  6. const FOUR_MINUTES = 4 * 60 * 1000;
  7. const wait = ms => new Promise(resolve => setTimeout(resolve, ms || 3000));
  8.  
  9. Element.prototype.isVisible = function() {
  10. return !!(this.offsetWidth||this.offsetHeight||this.getClientRects().length);
  11. };
  12. Element.prototype.isUserFriendly = function(selector) {
  13. let e = selector ? this.querySelector(selector) : this;
  14. return e && e.isVisible() ? e : null;
  15. };
  16. Document.prototype.isUserFriendly = Element.prototype.isUserFriendly;
  17.  
  18. class CrawlerWidget {
  19. constructor(params) {
  20. if (!params || !params.selector) {
  21. throw new Error('CrawlerWidget requires a selector parameter');
  22. }
  23. this.context = this.context || document;
  24. Object.assign(this, params);
  25. }
  26.  
  27. get isUserFriendly() {
  28. this.element = this.context.isUserFriendly(this.selector);
  29. return this.element;
  30. }
  31. }
  32.  
  33. class CaptchaWidget extends CrawlerWidget {
  34. constructor(params) {
  35. super(params);
  36. }
  37.  
  38. solve() { return true; }
  39.  
  40. async isSolved() { return false; }
  41. }
  42.  
  43. class HCaptchaWidget extends CaptchaWidget {
  44. constructor(params) {
  45. let defaultParams = {
  46. selector: '.h-captcha > iframe',
  47. waitMs: [1000, 5000],
  48. timeoutMs: FOUR_MINUTES
  49. };
  50. for (let p in params) {
  51. defaultParams[p] = params[p];
  52. }
  53. super(defaultParams);
  54. }
  55.  
  56. async isSolved() {
  57. return wait().then( () => {
  58. if (this.isUserFriendly && this.element.hasAttribute('data-hcaptcha-response') && this.element.getAttribute('data-hcaptcha-response').length > 0) {
  59. return Promise.resolve(true);
  60. }
  61. return this.isSolved();
  62. });
  63. }
  64. }

QingJ © 2025

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