注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
?_=1
来访问最新页面。https://zh.moegirl.org.cn/User:Bhsd/js/PreLangMark.js?_=1
/** * @Source: [[User:GuoPC/js/PreLangMark.js]] * @Author: [[User:GuoPC]] * @ModifiedBy: [[User:Leranjun]], [[User:Bhsd]] */ mw.loader.addStyleTag(`.preLangWrap { position: relative; display: flow-root; } .preLangWrap::after { content: attr(lang); position: absolute; top: 0; right: 0; padding: 5px 10px; color: #222; font-family: 'Product Sans', 'Source Sans Pro', Tahoma, sans-serif; font-size: 0.8em; line-height: 1.25; font-weight: 700; text-transform: uppercase; } .skin-moeskin .preLangWrap::after { /* by [[User:GuoPC]] */ top: 12px; right: 6px; } .preLangWrap > pre[lang] { padding-top: 20px; margin-top: 0; } `); mw.hook( 'wikipage.content' ).add($content => { const langs = {javascript: 'js', css: 'css', 'sanitized-css': 'css', Scribunto: 'lua'}, $pre = $content.find( 'pre' ); $pre.filter( '.mw-code' ).attr('lang', langs[ mw.config.get( 'wgPageContentModel' ) ]); $pre.not( '[lang]' ).each(function() { const className = [...this.classList].find(ele => ele.startsWith( 'lang-' )); if (className) { this.lang = className.slice(5); } }); $pre.filter( '[lang]' ).each(function() { $(this).wrap( $('<div>', {class: 'preLangWrap', lang: this.lang}) ); }); });