Greasy Fork

百家号文章标题h[x]层级标准化

修正百家号文章的层级,配合copy as markdown插件食用

// ==UserScript==
// @name         百家号文章标题h[x]层级标准化
// @namespace    https://mbd.baidu.com
// @version      0.2
// @description  修正百家号文章的层级,配合copy as markdown插件食用
// @author       dexfire
// @icon         https://q2.qlogo.cn/headimg_dl?dst_uin=275176629&spec=5
// @match        https://mbd.baidu.com/newspage/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    // Your code here...
    // replace the Elements with $(src) with a tag with type of dist.
    // such as `replace_tag('bjh-h3', 'h3')`
    function replace_tag(src, dist){
        var jsrc = $('.' + src);
        jsrc.each(function(){
            var e = $(this);
            var p = $('<p></p>');
            var jdist = $('<' + dist + ' class="' + src + '"></' + dist +'>');
            jdist.append(e.contents());
            p.append(jdist);
            if (e.parent() !== null){
                e.parent().after(p);
                e.parent().remove();
            }
        });
    }

    replace_tag('bjh-h3', 'h2');
    replace_tag('bjh-blockquote', 'quote');
})();