DOMParser

DOMParser is a script

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

  1. // ==UserScript==
  2. // @name DOMParser
  3. // @namespace https://gf.qytechs.cn/en/users/8332-sreyemnayr
  4. // @version 2018.4.4.2
  5. // @description DOMParser is a script
  6. // @author sreyemnayr
  7. // ==/UserScript==
  8.  
  9. "use strict";
  10.  
  11. (function ($, undefined) {
  12. var dom_parser = false;
  13.  
  14. // based on: https://developer.mozilla.org/en/DOMParser
  15. // does not work with IE < 9
  16. // Firefox/Opera/IE throw errors on unsupported types
  17. try {
  18. // WebKit returns null on unsupported types
  19. if ((new DOMParser()).parseFromString("", "text/html")) {
  20. // text/html parsing is natively supported
  21. dom_parser = true;
  22. }
  23. } catch (ex) {}
  24.  
  25. if (dom_parser) {
  26. $.parseHTML = function (html) {
  27. return new DOMParser().parseFromString(html, "text/html");
  28. };
  29. }
  30. else if (document.implementation && document.implementation.createHTMLDocument) {
  31. $.parseHTML = function (html) {
  32. var doc = document.implementation.createHTMLDocument("");
  33. var doc_el = doc.documentElement;
  34.  
  35. doc_el.innerHTML = html;
  36.  
  37. var els = [], el = doc_el.firstChild;
  38.  
  39. while (el) {
  40. if (el.nodeType === 1) els.push(el);
  41. el = el.nextSibling;
  42. }
  43.  
  44. // are we dealing with an entire document or a fragment?
  45. if (els.length === 1 && els[0].localName.toLowerCase() === "html") {
  46. doc.removeChild(doc_el);
  47. el = doc_el.firstChild;
  48. while (el) {
  49. var next = el.nextSibling;
  50. doc.appendChild(el);
  51. el = next;
  52. }
  53. }
  54. else {
  55. el = doc_el.firstChild;
  56. while (el) {
  57. var next = el.nextSibling;
  58. if (el.nodeType !== 1 && el.nodeType !== 3) doc.insertBefore(el,doc_el);
  59. el = next;
  60. }
  61. }
  62.  
  63. return doc;
  64. };
  65. }
  66. })(jQuery);

QingJ © 2025

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