htmlToElements

Convert html source text to dom elements.

目前為 2020-08-29 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/410153/842393/htmlToElements.js

  1. // ==UserScript==
  2. // @name htmlToElements
  3. // @namespace https://github.com
  4. // @version 0.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. };