MediaWiki:Gadget-code-prettify.js:修订间差异

H萌娘,万物皆可H的百科全书!
跳到导航 跳到搜索
imported>=海豚=
无编辑摘要
imported>=海豚=
无编辑摘要
 
(未显示同一用户的11个中间版本)
第1行: 第1行:
(function($, mw) {
mw.loader.load('https://cdn.jsdelivr.net/gh/bhsd-harry/LLWiki@2.4/js/gadget-code-prettify.min.js','text/javascript');
   if (mw.config.get('wgPageName').match(/\.js$/)) $('.mw-code').addClass('prettyprint linenums lang-js');
   if (mw.config.get('wgPageName').match(/\.css$/)) $('.mw-code').addClass('prettyprint linenums lang-css');
   var acceptsLangs = {
     "js": "js",
     "javascript": "js",
     "css": "css",
     "html": "html",
     "scribunto": "lua",
     "lua": "lua"
   };
   var wgPageContentModel = mw.config.get("wgPageContentModel", "").toLowerCase();
   if (wgPageContentModel in acceptsLangs) {
     $('.mw-code').addClass('prettyprint linenums lang-' + acceptsLangs[wgPageContentModel]);
   }
   $('pre[lang]').each(function() {
     var self = $(this);
     var lang = self.attr("lang").toLowerCase();
     if (lang in acceptsLangs) {
       self.addClass("prettyprint linenums lang-" + acceptsLangs[lang]);
     }
   });
   if ($('.prettyprint').length > 0) {
     $.ajax({
       url: mw.config.get("wgServer") + mw.config.get("wgScriptPath") + '/index.php?title=MediaWiki:Gadget-code-prettify-core.js&action=raw&ctype=text/javascript',
       dataType: 'script',
       cache: true,
       success: function() {
         prettyPrint();
         if (mw.config.get('wgPageName').match(/\.(js|css)$/)) {
           $(window).on("hashchange", function() {
             var frag = new mw.Uri().fragment;
             if (/^L\d+$/.test(frag)) {
               var firstCode = $("#" + frag)[0] || $(".prettyprint.prettyprinted > .linenums").first().children().eq(+frag.substring(1) - 1)[0];
               if (firstCode) {
                 $('html, body').animate({
                   scrollTop: $(firstCode).offset().top,
                 });
               }
             }
           }).trigger("hashchange");
         }
       }
     });
   }
})(jQuery, mediaWiki);

2021年6月8日 (二) 20:36的最新版本

mw.loader.load('https://cdn.jsdelivr.net/gh/bhsd-harry/[email protected]/js/gadget-code-prettify.min.js','text/javascript');