Greasy Fork

Greasy Fork is available in English.

编程猫html修复【较为安全】

编程猫html修复,对iframe/embed进行了防范

当前为 2024-08-29 提交的版本,查看 最新版本

// ==UserScript==
// @name         编程猫html修复【较为安全】
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  编程猫html修复,对iframe/embed进行了防范
// @author       Fantasy
// @match        https://shequ.codemao.cn/*
// @match        https://kitten4.codemao.cn/*
// @grant        none
// @require      https://code.jquery.com/jquery-3.6.0.min.js
// @require      https://cdn.jsdelivr.net/npm/[email protected]/jquery.cookie.min.js
// @license MIT
// @icon         https://static.codemao.cn/FjCi6RLz1-HB5C47m7M_0gZqJNDG
// @run-at       document-end
// ==/UserScript==

console.log('编程猫html修复已启用')

function edit_html(){
    $('.r-community-r-detail--forum_content,.r-community-r-detail-c-comment_item--content').each(function(){
        let old_content_str = $(this).html().replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/<(embed|iframe)[^>]*?(src=[^>]*?work[^>]*?|style=[^>]*?position[^>]*?)[^>]*?>/gi,'').replace('<p style="color:orange">【检测到html格式排版,已自动修复】</p>','')
        $(this).text('').append(`${old_content_str} ${old_content_str.includes('<') ? '<p style="color:orange">【检测到html格式排版,已自动修复】</p>' : ''}`)
    })


}

function wait_for_js(fun,selecter){
   let wait_js = setInterval(function(){
        if($(selecter).length !== 0){
            clearInterval(wait_js)
            fun()
        }
    })
}
if(window.location.href.includes("https://shequ.codemao.cn/wiki") ||window.location.href.includes("https://shequ.codemao.cn/community/")){
    setInterval(edit_html,100)
}