htmlToElements

Convert html source text to dom elements.

目前为 2021-04-09 提交的版本。查看 最新版本

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

  1. // ==UserScript==
  2. // @name htmlToElements
  3. // @namespace https://greasyfork.org
  4. // @version 0.1.1
  5. // @description Convert html source text to dom elements.
  6. // @match *://*/*
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. /**
  11. * https://stackoverflow.com/a/35385518
  12. * @param {String} HTML representing any number of sibling elements
  13. * @return {NodeList}
  14. */
  15. const htmlToElements = (htmlSrc) => {
  16. let template = document.createElement('template');
  17. template.innerHTML = htmlSrc;
  18. return template.content;
  19. };