Use Javascript Bookmarklet to Chunk Page Content by Headings

前端 未结 2 594
长发绾君心
长发绾君心 2021-01-24 16:12

I\'ve got an HTML page that is compiled dynamically from a database that I need to restyle and restructure. It looks messy, I know, but what I\'m working with is this (note: no

2条回答
  •  走了就别回头了
    2021-01-24 16:40

    You could insert jQuery from the bookmarklet, and then it's rather easy:

    function a() {
        var names = {'h1': 'one',
                     'h2': 'two',
                     'h3': 'three',
                     'h4': 'four',
                     'h5': 'five',
                     'h6': 'six'};
        var i = 1;
        jQuery('*').filter(":header").each(function() {
            jQuery(this)
            .add(jQuery(this)
                .nextUntil( jQuery("*")
                            .filter(":header")) )
                .wrapAll( jQuery("
    ") ); }); }; (function(){ var s=document.createElement('script'); s.src='http://code.jquery.com/jquery-1.6.1.js'; document.getElementsByTagName('head')[0].appendChild(s); s.onload = function(){ setTimeout(a, 500); }; })();

    Or, in one line:

    javascript:function a(){var b={h1:"one",h2:"two",h3:"three",h4:"four",h5:"five",h6:"six"};jQuery("*").filter(":header").each(function(){jQuery(this).add(jQuery(this).nextUntil(jQuery("*").filter(":header"))).wrapAll(jQuery("
    "))})}(function(){var b=document.createElement("script");b.src="http://code.jquery.com/jquery-1.6.1.js";document.getElementsByTagName("head")[0].appendChild(b);b.onload=function(){setTimeout(a,500)}})();

提交回复
热议问题