Jump to content
Wikimedia Meta-Wiki

User:He7d3r/Tools/LanguageConverter.js: Difference between revisions

From Meta, a Wikimedia project coordination wiki
Content deleted Content added
m Sync with https://github.com/he7d3r/mw-gadget-LanguageConverter; minify with UgliPyJS 0.2.5
m Sync with https://github.com/he7d3r/mw-gadget-LanguageConverter; minify with UgliPyJS 0.2.5
Line 15: Line 15:
*/
*/
// <nowiki>
// <nowiki>
window.LanguageConverter===void 0&&(window.LanguageConverter={}),function(e,n,t){"use strict";t.version="2.35",t.cookie=(削除) e.config.get( (削除ここまで)"(削除) wgCookiePrefix")+"- (削除ここまで)lang-variant",t.dictionary===void 0&&(t.dictionary={}),t.variant_links={},t.mustReload=!1,t.getLocalMsg=function(n){var i=t.settings.msg,o=i[n];if(typeof o=="string")return o;if(typeof o=="object"){if(o[t.lang])return o[t.lang];if(o[e.config.get("wgContentLanguage")])return o[e.config.get("wgContentLanguage")];if(o.en)return o.en}return!1},t.get_URL_variant=function(){var n=e.util.getParamValue("variant"),i=t.settings.variants_list;return i[n]?n:null},t.get_cookie_variant=function(){var (削除) e= (削除ここまで)n.cookie(t.cookie),i=t.settings.variants_list;return i[(削除) e (削除ここまで)]?(削除) e (削除ここまで):null},t.get_preferred_variant=function(){var n=t.get_URL_variant()||t.get_cookie_variant()||e.config.get("wgContentLanguage");return n},t.toggle_visibility=function(){var e=!t.settings.show_changes;t.settings.show_changes=e,t.$target.toggleClass("show-changes",e),n("#ca-conv-show-hide-changes").find("a").text(e?t.getLocalMsg("hide_changes_link"):t.getLocalMsg("show_changes_link"))},t.createPortlet=function(){var i,o=e.config.get("skin");switch(o){case"vector":n("#p-variants").after(n("#p-cactions").clone().find("ul").empty().end().attr({id:"p-variants-js"}).find("span").text(t.getLocalMsg("menu_title")).addClass("flag-"+t.lang).end());break;default:i=n("#p-tb").clone().attr("id","p-variants-js").find("li").remove().end().find("h5").text(t.getLocalMsg("menu_title")).end().insertBefore("#p-tb")}},t.render_navigation=function(){var i,o,a=t.settings.variants_list,s=t.settings.show_changes,r=e.config.get("skin"),g=function(n){return function(i){i.preventDefault(),n!==t.lang&&(t.mustReload?location.href=e.util.getUrl(null,{variant:n}):t.startConversion(n))}};t.$target.toggleClass("show-changes",s),t.createPortlet();for(i in a)a[i]!==null&&(o=i===t.lang&&r==="vector",n(e.util.addPortletLink("p-variants-js","#",a[i],"ca-conv-"+i)).toggleClass("selected",o).click(g(i)),o&&n("#p-variants-js").find("span").text(a[i]));t.settings.help_page&&t.getLocalMsg("help_page_link")&&e.util.addPortletLink("p-variants-js",e.util.getUrl(t.settings.help_page),t.getLocalMsg("help_page_link"),"ca-conv-help-page"),t.getLocalMsg("show_changes_link")&&t.getLocalMsg("hide_changes_link")&&n(e.util.addPortletLink("p-variants-js","#",s?t.getLocalMsg("hide_changes_link"):t.getLocalMsg("show_changes_link"),"ca-conv-show-hide-changes")).click(function(e){e.preventDefault(),t.toggle_visibility()}),n("#ca-conv-show-hide-changes").toggle(t.lang!==e.config.get("wgContentLanguage"))},t.conv_typo_text=function(e){var n,i,o=t.regTypoChanges.length;for(n=0;o>n;n+=1){i=t.regTypoChanges[n];try{e=e.replace(i[0],i[1])}catch(a){alert(t.getLocalMsg("error_typo_processing")+i[0]+": "+i[1]+".\n\n"+a.message)}}return e},t.conv_typo_node=function(e){var n;if(e.nodeType===3)e.data=t.conv_typo_text(e.data);else for(n=0;e.childNodes.length>n;n+=1)e.id==="editform"||e.className.match(t.regClass)||t.conv_typo_node(e.childNodes[n])},t.conv_typo_document=function(){t.isAllowed()&&(document.title=t.conv_typo_text(document.title),t.conv_typo_node(t.$target[0]))},t.reg_split=function(e,n){var t,i,o,a,s=[],r=0,g=(n.ignoreCase?"i":"")+(n.multiline?"m":"")+(n.sticky?"y":"");n=RegExp(n.source,g+"g");var c=/()??/.exec("")[1]===void 0;e+="",c||(t=RegExp("^"+n.source+"$(?!\\s)",g)),i=n.exec(e);var l=function(){var e;for(e=1;arguments.length-2>e;e+=1)arguments[e]===void 0&&(i[e]=void 0)};while(i)o=i.index+i[0].length,o>r&&(s.push(e.slice(r,i.index)),!c&&i.length>1&&i[0].replace(t,l),i.length>1&&e.length>i.index&&Array.prototype.push.apply(s,i.slice(1)),a=i[0].length,r=o),n.lastIndex===i.index&&(n.lastIndex+=1),i=n.exec(e);return r===e.length?(!n.test("")||a)&&s.push(""):s.push(e.slice(r)),s},t.conv_text_from_dic=function(n,i){var o,a,s,r,g,c,l,p,d,_,u,h,f=RegExp("([^"+t.settings.word_chars+"]+)",""),v=t.reg_split(n,f),m=null,w=t.dictionary;n="",i&&(c=['<span class="v-'+t.lang+'" title="',null,'">',null,"</span>"]);e:for(o=0,s=v.length;s>o;o+=1)if(l=v[o])try{for(r=t.settings.max_seq;r>0;r-=1)if(!(o+2*(r-1)>=s)){for(a=1,g=l;r>a;a+=1)g+=" "+v[o+2*a];if(d=w.hasOwnProperty(g)?w[g]:null,d||(_=g.toLowerCase(),u=g[0].toUpperCase()+_.substring(1),h=g.toUpperCase(),h===g?w.hasOwnProperty(u)?d=w[u].toUpperCase():w.hasOwnProperty(_)&&(d=w[_].toUpperCase()):u===g&&w.hasOwnProperty(_)&&(d=w[_][0].toUpperCase()+w[_].substring(1))),d){i?(c[1]=e.html.escape(g),c[3]=e.html.escape(d),n+=c.join("")):n+=e.html.escape(d),m=!0,o+=2*r-2;continue e}}"&"===l&&"fr"===e.config.get("wgContentLanguage")?(p=v[o-2],d=p&&p===p.toUpperCase()?"ET":"et",i?(c[1]=e.html.escape(l),c[3]=e.html.escape(d),n+=c.join("")):n+=e.html.escape(d),m=!0):n+=e.html.escape(l)}catch(y){alert(t.getLocalMsg("error_word_processing")+v[o]+".\n\n"+y.message)}return m?n:null},t.conv_node_from_dic=function(e){var i,o,a=!0;if(e.nodeType===3)i=t.conv_text_from_dic(e.data,a),i&&n(e).replaceWith(i);else for(o=0;e.childNodes.length>o;o+=1)e.id==="editform"||e.className.match(t.regClass)||t.conv_node_from_dic(e.childNodes[o])},t.conv_callback=function(i){t.conv_typo_document();var o,a,s,r,g,c,l,p,d,_,u,h,f,v,m=t.settings.global_dic_page[t.lang],w=[],y=e.config.get("skin");if(!m)return alert(t.getLocalMsg("error_missing_dict_name")+t.lang),n.removeSpinner("var-spinner"),!1;if(!i)return n.removeSpinner("var-spinner"),!1;if(o=i.query,o&&(a=o.pages,s=o.pageids),!o||!a||!s)return n.removeSpinner("var-spinner"),!1;for(typeof m=="object"&&(m=m.pages||m.page),m=m.split("|"),d=0;s.length>d;d+=1)a[s[d]].pageid?w.push([a[s[d]].revisions[0]["*"],m.indexOf(a[s[d]].title)]):(alert(t.getLocalMsg("error_missing_dict")+a[s[d]].title),location.href=e.util.getUrl(null,{variant:e.config.get("wgContentLanguage")}));if(!w.length)return n.removeSpinner("var-spinner"),void 0;for(w.sort(function(e,n){return e[1]-n[1]}),d=0;w.length>d;d+=1){r=w[d][0],g=r.split("\n");for(c in g)h=/^\*\s*(\S[^:]*?)\s*:\s*([\S].*?)\s*(?:\/\/.*?)?$/.exec(g[c]),h&&(t.dictionary[h[1]]=h[2])}if(_=t.settings.local_dic_id,_&&(_=_[t.lang]),u=_?document.getElementById(_):null){r=u.innerHTML,g=r.split("\n");for(d in g)h=/(?:^|<ul>)<li>\s*(\S[^:]*?)(?:\s|&#160;|&nbsp;)*:\s*([\S].*?)\s*(?:\/\/.*?)?<\/li>(?:$|<\/ul>)/i.exec(g[d]),h&&(t.dictionary[h[1]]=h[2])}(削除) n (削除ここまで).cookie(t.cookie,t.lang,{expires:(削除) 7 (削除ここまで),path:"/",secure:t.secure}),v=!1,l=t.conv_text_from_dic(document.title,v),l&&(document.title=l),t.conv_node_from_dic(t.$target[0]),f=t.settings.variants_list;for(p in f)f[p]!==null&&n("#ca-conv-"+p).toggleClass("selected",p===t.lang&&y==="vector");t.settings.show_menu_title&&n("#p-variants-js").find("span").text(f[t.lang]).attr("class","flag-"+t.lang),n("#ca-conv-show-hide-changes").toggle(t.lang!==e.config.get("wgContentLanguage")),t.mustReload=!0,n.removeSpinner("var-spinner")},t.startConversion=function(i){var o,a,s,r,g,c,l;if(t.lang=i,t.regClass=RegExp("(?:\\s|^)(?:v-"+t.lang+"|diff-(?:context|deletedline|addedline)|"+t.settings.no_conversion_class+")(?:\\s|$)"),t.regTypoChanges=[],r=t.settings.typo_changes,r&&(r=r[t.lang]),r)if(r.constructor===Array)for(o=0;r.length>o;o+=1)g=r[o],g.length===2&&g[1]!==null&&(typeof g[0]=="string"&&(g[0]=RegExp(e.util.escapeRegExp(g[0]),"g")),t.regTypoChanges.push(g));else if(r.constructor===Object)for(o in r)if(r.hasOwnProperty&&r[o]!==null)try{a=RegExp(e.util.escapeRegExp(o),"g"),t.regTypoChanges.push([a,r[o]])}catch(p){alert(t.getLocalMsg("error_typo_processing")+o+": "+r[o]+".\n\n"+p.message)}return i===e.config.get("wgContentLanguage")?!1:(n("#p-variants-js").injectSpinner({id:"var-spinner"}),s=t.settings.global_dic_page[t.lang],typeof s=="object"?(c=s.api,typeof c=="object"&&c.length===2&&(c=t.secure?c[1]:c[0]),s=s.pages||s.page,l=c===e.config.get("wgServer")+e.util.wikiScript("api")?"json":"jsonp"):(c=e.util.wikiScript("api"),l="json"),n.ajax({url:c,dataType:l,data:{format:"json",action:"query",titles:s,prop:"revisions",rvprop:"content",indexpageids:"1"},success:t.conv_callback}),void 0)},t.isAllowed=function(){var n=t.settings.ns_list,i="*"===n||n[e.config.get("wgNamespaceNumber")],o=t.settings.local_dic_id,a=o[e.config.get("wgContentLanguage")]?document.getElementById(o[e.config.get("wgContentLanguage")]):!1;switch(t.settings.selection_mode){case"AND":if(!i||!a)return!1;break;case"OR":if(!i&&!a)return!1}return!0},t.load=function(){t.settings={msg:{error_missing_dict:"The following dictionary was not found:\n",error_missing_dict_name:"It is necessary to define the page name of the dictionary for ",error_word_processing:"Error has occurred while processing the following word:\n",error_typo_processing:"Error has occurred while processing the following typographic change:\n",help_page_link:"Open help page",show_changes_link:"Show changes",hide_changes_link:"Hide changes",menu_title:"Variants"},word_chars:"a-zA-Z'-",typo_changes:{},variants_list:{},ns_list:{0:!0},local_dic_id:"modernization",no_conversion_class:"no-conversion",global_dic_page:"Project:Dictionary",help_page:"Project:Language Converter",show_changes:!1,show_menu_title:!0,selection_mode:"AND",max_seq:3},n.extend(!0,t.settings,t.config),t.isAllowed()&&(t.secure=location.protocol==="https:",t.$target=n("#content"),t.$target.length||(t.$target=n("#mw-content-text")),t.lang=t.get_preferred_variant(),(削除) n (削除ここまで).cookie(t.cookie,t.lang,{expires:(削除) 7 (削除ここまで),path:"/",secure:t.secure}),t.render_navigation(),t.startConversion(t.lang))},n.when(e.loader.using(["mediawiki.util","(削除) jquery (削除ここまで).cookie","jquery.spinner"]),n.ready).then(function(){t.load(),self.gadget_typographie&&!self.gadget_mod2&&t.conv_typo_document()})}(mediaWiki,jQuery,window.LanguageConverter);
window.LanguageConverter===void 0&&(window.LanguageConverter={}),function(e,n,t){"use strict";t.version="2.35",t.cookie="lang-variant",t.dictionary===void 0&&(t.dictionary={}),t.variant_links={},t.mustReload=!1,t.getLocalMsg=function(n){var i=t.settings.msg,o=i[n];if(typeof o=="string")return o;if(typeof o=="object"){if(o[t.lang])return o[t.lang];if(o[e.config.get("wgContentLanguage")])return o[e.config.get("wgContentLanguage")];if(o.en)return o.en}return!1},t.get_URL_variant=function(){var n=e.util.getParamValue("variant"),i=t.settings.variants_list;return i[n]?n:null},t.get_cookie_variant=function(){var n(追記) =e (追記ここまで).cookie(追記) .get (追記ここまで)(t.cookie),i=t.settings.variants_list;return i[(追記) n (追記ここまで)]?(追記) n (追記ここまで):null},t.get_preferred_variant=function(){var n=t.get_URL_variant()||t.get_cookie_variant()||e.config.get("wgContentLanguage");return n},t.toggle_visibility=function(){var e=!t.settings.show_changes;t.settings.show_changes=e,t.$target.toggleClass("show-changes",e),n("#ca-conv-show-hide-changes").find("a").text(e?t.getLocalMsg("hide_changes_link"):t.getLocalMsg("show_changes_link"))},t.createPortlet=function(){var i,o=e.config.get("skin");switch(o){case"vector":n("#p-variants").after(n("#p-cactions").clone().find("ul").empty().end().attr({id:"p-variants-js"}).find("span").text(t.getLocalMsg("menu_title")).addClass("flag-"+t.lang).end());break;default:i=n("#p-tb").clone().attr("id","p-variants-js").find("li").remove().end().find("h5").text(t.getLocalMsg("menu_title")).end().insertBefore("#p-tb")}},t.render_navigation=function(){var i,o,a=t.settings.variants_list,s=t.settings.show_changes,r=e.config.get("skin"),g=function(n){return function(i){i.preventDefault(),n!==t.lang&&(t.mustReload?location.href=e.util.getUrl(null,{variant:n}):t.startConversion(n))}};t.$target.toggleClass("show-changes",s),t.createPortlet();for(i in a)a[i]!==null&&(o=i===t.lang&&r==="vector",n(e.util.addPortletLink("p-variants-js","#",a[i],"ca-conv-"+i)).toggleClass("selected",o).click(g(i)),o&&n("#p-variants-js").find("span").text(a[i]));t.settings.help_page&&t.getLocalMsg("help_page_link")&&e.util.addPortletLink("p-variants-js",e.util.getUrl(t.settings.help_page),t.getLocalMsg("help_page_link"),"ca-conv-help-page"),t.getLocalMsg("show_changes_link")&&t.getLocalMsg("hide_changes_link")&&n(e.util.addPortletLink("p-variants-js","#",s?t.getLocalMsg("hide_changes_link"):t.getLocalMsg("show_changes_link"),"ca-conv-show-hide-changes")).click(function(e){e.preventDefault(),t.toggle_visibility()}),n("#ca-conv-show-hide-changes").toggle(t.lang!==e.config.get("wgContentLanguage"))},t.conv_typo_text=function(e){var n,i,o=t.regTypoChanges.length;for(n=0;o>n;n+=1){i=t.regTypoChanges[n];try{e=e.replace(i[0],i[1])}catch(a){alert(t.getLocalMsg("error_typo_processing")+i[0]+": "+i[1]+".\n\n"+a.message)}}return e},t.conv_typo_node=function(e){var n;if(e.nodeType===3)e.data=t.conv_typo_text(e.data);else for(n=0;e.childNodes.length>n;n+=1)e.id==="editform"||e.className.match(t.regClass)||t.conv_typo_node(e.childNodes[n])},t.conv_typo_document=function(){t.isAllowed()&&(document.title=t.conv_typo_text(document.title),t.conv_typo_node(t.$target[0]))},t.reg_split=function(e,n){var t,i,o,a,s=[],r=0,g=(n.ignoreCase?"i":"")+(n.multiline?"m":"")+(n.sticky?"y":"");n=RegExp(n.source,g+"g");var c=/()??/.exec("")[1]===void 0;e+="",c||(t=RegExp("^"+n.source+"$(?!\\s)",g)),i=n.exec(e);var l=function(){var e;for(e=1;arguments.length-2>e;e+=1)arguments[e]===void 0&&(i[e]=void 0)};while(i)o=i.index+i[0].length,o>r&&(s.push(e.slice(r,i.index)),!c&&i.length>1&&i[0].replace(t,l),i.length>1&&e.length>i.index&&Array.prototype.push.apply(s,i.slice(1)),a=i[0].length,r=o),n.lastIndex===i.index&&(n.lastIndex+=1),i=n.exec(e);return r===e.length?(!n.test("")||a)&&s.push(""):s.push(e.slice(r)),s},t.conv_text_from_dic=function(n,i){var o,a,s,r,g,c,l,p,d,_,u,h,f=RegExp("([^"+t.settings.word_chars+"]+)",""),v=t.reg_split(n,f),m=null,w=t.dictionary;n="",i&&(c=['<span class="v-'+t.lang+'" title="',null,'">',null,"</span>"]);e:for(o=0,s=v.length;s>o;o+=1)if(l=v[o])try{for(r=t.settings.max_seq;r>0;r-=1)if(!(o+2*(r-1)>=s)){for(a=1,g=l;r>a;a+=1)g+=" "+v[o+2*a];if(d=w.hasOwnProperty(g)?w[g]:null,d||(_=g.toLowerCase(),u=g[0].toUpperCase()+_.substring(1),h=g.toUpperCase(),h===g?w.hasOwnProperty(u)?d=w[u].toUpperCase():w.hasOwnProperty(_)&&(d=w[_].toUpperCase()):u===g&&w.hasOwnProperty(_)&&(d=w[_][0].toUpperCase()+w[_].substring(1))),d){i?(c[1]=e.html.escape(g),c[3]=e.html.escape(d),n+=c.join("")):n+=e.html.escape(d),m=!0,o+=2*r-2;continue e}}"&"===l&&"fr"===e.config.get("wgContentLanguage")?(p=v[o-2],d=p&&p===p.toUpperCase()?"ET":"et",i?(c[1]=e.html.escape(l),c[3]=e.html.escape(d),n+=c.join("")):n+=e.html.escape(d),m=!0):n+=e.html.escape(l)}catch(y){alert(t.getLocalMsg("error_word_processing")+v[o]+".\n\n"+y.message)}return m?n:null},t.conv_node_from_dic=function(e){var i,o,a=!0;if(e.nodeType===3)i=t.conv_text_from_dic(e.data,a),i&&n(e).replaceWith(i);else for(o=0;e.childNodes.length>o;o+=1)e.id==="editform"||e.className.match(t.regClass)||t.conv_node_from_dic(e.childNodes[o])},t.conv_callback=function(i){t.conv_typo_document();var o,a,s,r,g,c,l,p,d,_,u,h,f,v,m=t.settings.global_dic_page[t.lang],w=[],y=e.config.get("skin");if(!m)return alert(t.getLocalMsg("error_missing_dict_name")+t.lang),n.removeSpinner("var-spinner"),!1;if(!i)return n.removeSpinner("var-spinner"),!1;if(o=i.query,o&&(a=o.pages,s=o.pageids),!o||!a||!s)return n.removeSpinner("var-spinner"),!1;for(typeof m=="object"&&(m=m.pages||m.page),m=m.split("|"),d=0;s.length>d;d+=1)a[s[d]].pageid?w.push([a[s[d]].revisions[0]["*"],m.indexOf(a[s[d]].title)]):(alert(t.getLocalMsg("error_missing_dict")+a[s[d]].title),location.href=e.util.getUrl(null,{variant:e.config.get("wgContentLanguage")}));if(!w.length)return n.removeSpinner("var-spinner"),void 0;for(w.sort(function(e,n){return e[1]-n[1]}),d=0;w.length>d;d+=1){r=w[d][0],g=r.split("\n");for(c in g)h=/^\*\s*(\S[^:]*?)\s*:\s*([\S].*?)\s*(?:\/\/.*?)?$/.exec(g[c]),h&&(t.dictionary[h[1]]=h[2])}if(_=t.settings.local_dic_id,_&&(_=_[t.lang]),u=_?document.getElementById(_):null){r=u.innerHTML,g=r.split("\n");for(d in g)h=/(?:^|<ul>)<li>\s*(\S[^:]*?)(?:\s|&#160;|&nbsp;)*:\s*([\S].*?)\s*(?:\/\/.*?)?<\/li>(?:$|<\/ul>)/i.exec(g[d]),h&&(t.dictionary[h[1]]=h[2])}(追記) e (追記ここまで).cookie(追記) .set (追記ここまで)(t.cookie,t.lang,{expires:(追記) 604800 (追記ここまで),path:"/",secure:t.secure}),v=!1,l=t.conv_text_from_dic(document.title,v),l&&(document.title=l),t.conv_node_from_dic(t.$target[0]),f=t.settings.variants_list;for(p in f)f[p]!==null&&n("#ca-conv-"+p).toggleClass("selected",p===t.lang&&y==="vector");t.settings.show_menu_title&&n("#p-variants-js").find("span").text(f[t.lang]).attr("class","flag-"+t.lang),n("#ca-conv-show-hide-changes").toggle(t.lang!==e.config.get("wgContentLanguage")),t.mustReload=!0,n.removeSpinner("var-spinner")},t.startConversion=function(i){var o,a,s,r,g,c,l;if(t.lang=i,t.regClass=RegExp("(?:\\s|^)(?:v-"+t.lang+"|diff-(?:context|deletedline|addedline)|"+t.settings.no_conversion_class+")(?:\\s|$)"),t.regTypoChanges=[],r=t.settings.typo_changes,r&&(r=r[t.lang]),r)if(r.constructor===Array)for(o=0;r.length>o;o+=1)g=r[o],g.length===2&&g[1]!==null&&(typeof g[0]=="string"&&(g[0]=RegExp(e.util.escapeRegExp(g[0]),"g")),t.regTypoChanges.push(g));else if(r.constructor===Object)for(o in r)if(r.hasOwnProperty&&r[o]!==null)try{a=RegExp(e.util.escapeRegExp(o),"g"),t.regTypoChanges.push([a,r[o]])}catch(p){alert(t.getLocalMsg("error_typo_processing")+o+": "+r[o]+".\n\n"+p.message)}return i===e.config.get("wgContentLanguage")?!1:(n("#p-variants-js").injectSpinner({id:"var-spinner"}),s=t.settings.global_dic_page[t.lang],typeof s=="object"?(c=s.api,typeof c=="object"&&c.length===2&&(c=t.secure?c[1]:c[0]),s=s.pages||s.page,l=c===e.config.get("wgServer")+e.util.wikiScript("api")?"json":"jsonp"):(c=e.util.wikiScript("api"),l="json"),n.ajax({url:c,dataType:l,data:{format:"json",action:"query",titles:s,prop:"revisions",rvprop:"content",indexpageids:"1"},success:t.conv_callback}),void 0)},t.isAllowed=function(){var n=t.settings.ns_list,i="*"===n||n[e.config.get("wgNamespaceNumber")],o=t.settings.local_dic_id,a=o[e.config.get("wgContentLanguage")]?document.getElementById(o[e.config.get("wgContentLanguage")]):!1;switch(t.settings.selection_mode){case"AND":if(!i||!a)return!1;break;case"OR":if(!i&&!a)return!1}return!0},t.load=function(){t.settings={msg:{error_missing_dict:"The following dictionary was not found:\n",error_missing_dict_name:"It is necessary to define the page name of the dictionary for ",error_word_processing:"Error has occurred while processing the following word:\n",error_typo_processing:"Error has occurred while processing the following typographic change:\n",help_page_link:"Open help page",show_changes_link:"Show changes",hide_changes_link:"Hide changes",menu_title:"Variants"},word_chars:"a-zA-Z'-",typo_changes:{},variants_list:{},ns_list:{0:!0},local_dic_id:"modernization",no_conversion_class:"no-conversion",global_dic_page:"Project:Dictionary",help_page:"Project:Language Converter",show_changes:!1,show_menu_title:!0,selection_mode:"AND",max_seq:3},n.extend(!0,t.settings,t.config),t.isAllowed()&&(t.secure=location.protocol==="https:",t.$target=n("#content"),t.$target.length||(t.$target=n("#mw-content-text")),t.lang=t.get_preferred_variant(),(追記) e (追記ここまで).cookie(追記) .set (追記ここまで)(t.cookie,t.lang,{expires:(追記) 604800 (追記ここまで),path:"/",secure:t.secure}),t.render_navigation(),t.startConversion(t.lang))},n.when(e.loader.using(["mediawiki.util","(追記) mediawiki (追記ここまで).cookie","jquery.spinner"]),n.ready).then(function(){t.load(),self.gadget_typographie&&!self.gadget_mod2&&t.conv_typo_document()})}(mediaWiki,jQuery,window.LanguageConverter);
// </nowiki>
// </nowiki>

Revision as of 11:45, 24 February 2024

 // [[File:User:He7d3r/Tools/LanguageConverter.js]] (workaround for [[phab:T35355]])
 /*jslint browser: true, white: true, todo: true, continue: true, forin: true, vars: true, devel: true, regexp: true */
 /*global jQuery, mediaWiki, LanguageConverter, self */
 /**
  * Based on [[oldwikisource:MediaWiki:Modernisation.js]]
  * @author: [[:fr:User:ThomasV]]
  * @author: [[w:fr:User:Phe]]
  * @author: [[s:fr:User:Tpt]] (https://github.com/Tpt)
  * @author: Helder (https://github.com/he7d3r)
  * @license: CC BY-SA 3.0 <https://creativecommons.org/licenses/by-sa/3.0/>
  */
 // <nowiki>
 /**
  * Setup the Language Converter global:
  */
 // <nowiki>
 window.LanguageConverter===void0&&(window.LanguageConverter={}),function(e,n,t){"use strict";t.version="2.35",t.cookie="lang-variant",t.dictionary===void0&&(t.dictionary={}),t.variant_links={},t.mustReload=!1,t.getLocalMsg=function(n){vari=t.settings.msg,o=i[n];if(typeofo=="string")returno;if(typeofo=="object"){if(o[t.lang])returno[t.lang];if(o[e.config.get("wgContentLanguage")])returno[e.config.get("wgContentLanguage")];if(o.en)returno.en}return!1},t.get_URL_variant=function(){varn=e.util.getParamValue("variant"),i=t.settings.variants_list;returni[n]?n:null},t.get_cookie_variant=function(){varn=e.cookie.get(t.cookie),i=t.settings.variants_list;returni[n]?n:null},t.get_preferred_variant=function(){varn=t.get_URL_variant()||t.get_cookie_variant()||e.config.get("wgContentLanguage");returnn},t.toggle_visibility=function(){vare=!t.settings.show_changes;t.settings.show_changes=e,t.$target.toggleClass("show-changes",e),n("#ca-conv-show-hide-changes").find("a").text(e?t.getLocalMsg("hide_changes_link"):t.getLocalMsg("show_changes_link"))},t.createPortlet=function(){vari,o=e.config.get("skin");switch(o){case"vector":n("#p-variants").after(n("#p-cactions").clone().find("ul").empty().end().attr({id:"p-variants-js"}).find("span").text(t.getLocalMsg("menu_title")).addClass("flag-"+t.lang).end());break;default:i=n("#p-tb").clone().attr("id","p-variants-js").find("li").remove().end().find("h5").text(t.getLocalMsg("menu_title")).end().insertBefore("#p-tb")}},t.render_navigation=function(){vari,o,a=t.settings.variants_list,s=t.settings.show_changes,r=e.config.get("skin"),g=function(n){returnfunction(i){i.preventDefault(),n!==t.lang&&(t.mustReload?location.href=e.util.getUrl(null,{variant:n}):t.startConversion(n))}};t.$target.toggleClass("show-changes",s),t.createPortlet();for(iina)a[i]!==null&&(o=i===t.lang&&r==="vector",n(e.util.addPortletLink("p-variants-js","#",a[i],"ca-conv-"+i)).toggleClass("selected",o).click(g(i)),o&&n("#p-variants-js").find("span").text(a[i]));t.settings.help_page&&t.getLocalMsg("help_page_link")&&e.util.addPortletLink("p-variants-js",e.util.getUrl(t.settings.help_page),t.getLocalMsg("help_page_link"),"ca-conv-help-page"),t.getLocalMsg("show_changes_link")&&t.getLocalMsg("hide_changes_link")&&n(e.util.addPortletLink("p-variants-js","#",s?t.getLocalMsg("hide_changes_link"):t.getLocalMsg("show_changes_link"),"ca-conv-show-hide-changes")).click(function(e){e.preventDefault(),t.toggle_visibility()}),n("#ca-conv-show-hide-changes").toggle(t.lang!==e.config.get("wgContentLanguage"))},t.conv_typo_text=function(e){varn,i,o=t.regTypoChanges.length;for(n=0;o>n;n+=1){i=t.regTypoChanges[n];try{e=e.replace(i[0],i[1])}catch(a){alert(t.getLocalMsg("error_typo_processing")+i[0]+": "+i[1]+".\n\n"+a.message)}}returne},t.conv_typo_node=function(e){varn;if(e.nodeType===3)e.data=t.conv_typo_text(e.data);elsefor(n=0;e.childNodes.length>n;n+=1)e.id==="editform"||e.className.match(t.regClass)||t.conv_typo_node(e.childNodes[n])},t.conv_typo_document=function(){t.isAllowed()&&(document.title=t.conv_typo_text(document.title),t.conv_typo_node(t.$target[0]))},t.reg_split=function(e,n){vart,i,o,a,s=[],r=0,g=(n.ignoreCase?"i":"")+(n.multiline?"m":"")+(n.sticky?"y":"");n=RegExp(n.source,g+"g");varc=/()??/.exec("")[1]===void0;e+="",c||(t=RegExp("^"+n.source+"$(?!\\s)",g)),i=n.exec(e);varl=function(){vare;for(e=1;arguments.length-2>e;e+=1)arguments[e]===void0&&(i[e]=void0)};while(i)o=i.index+i[0].length,o>r&&(s.push(e.slice(r,i.index)),!c&&i.length>1&&i[0].replace(t,l),i.length>1&&e.length>i.index&&Array.prototype.push.apply(s,i.slice(1)),a=i[0].length,r=o),n.lastIndex===i.index&&(n.lastIndex+=1),i=n.exec(e);returnr===e.length?(!n.test("")||a)&&s.push(""):s.push(e.slice(r)),s},t.conv_text_from_dic=function(n,i){varo,a,s,r,g,c,l,p,d,_,u,h,f=RegExp("([^"+t.settings.word_chars+"]+)",""),v=t.reg_split(n,f),m=null,w=t.dictionary;n="",i&&(c=['<span class="v-'+t.lang+'" title="',null,'">',null,"</span>"]);e:for(o=0,s=v.length;s>o;o+=1)if(l=v[o])try{for(r=t.settings.max_seq;r>0;r-=1)if(!(o+2*(r-1)>=s)){for(a=1,g=l;r>a;a+=1)g+=" "+v[o+2*a];if(d=w.hasOwnProperty(g)?w[g]:null,d||(_=g.toLowerCase(),u=g[0].toUpperCase()+_.substring(1),h=g.toUpperCase(),h===g?w.hasOwnProperty(u)?d=w[u].toUpperCase():w.hasOwnProperty(_)&&(d=w[_].toUpperCase()):u===g&&w.hasOwnProperty(_)&&(d=w[_][0].toUpperCase()+w[_].substring(1))),d){i?(c[1]=e.html.escape(g),c[3]=e.html.escape(d),n+=c.join("")):n+=e.html.escape(d),m=!0,o+=2*r-2;continuee}}"&"===l&&"fr"===e.config.get("wgContentLanguage")?(p=v[o-2],d=p&&p===p.toUpperCase()?"ET":"et",i?(c[1]=e.html.escape(l),c[3]=e.html.escape(d),n+=c.join("")):n+=e.html.escape(d),m=!0):n+=e.html.escape(l)}catch(y){alert(t.getLocalMsg("error_word_processing")+v[o]+".\n\n"+y.message)}returnm?n:null},t.conv_node_from_dic=function(e){vari,o,a=!0;if(e.nodeType===3)i=t.conv_text_from_dic(e.data,a),i&&n(e).replaceWith(i);elsefor(o=0;e.childNodes.length>o;o+=1)e.id==="editform"||e.className.match(t.regClass)||t.conv_node_from_dic(e.childNodes[o])},t.conv_callback=function(i){t.conv_typo_document();varo,a,s,r,g,c,l,p,d,_,u,h,f,v,m=t.settings.global_dic_page[t.lang],w=[],y=e.config.get("skin");if(!m)returnalert(t.getLocalMsg("error_missing_dict_name")+t.lang),n.removeSpinner("var-spinner"),!1;if(!i)returnn.removeSpinner("var-spinner"),!1;if(o=i.query,o&&(a=o.pages,s=o.pageids),!o||!a||!s)returnn.removeSpinner("var-spinner"),!1;for(typeofm=="object"&&(m=m.pages||m.page),m=m.split("|"),d=0;s.length>d;d+=1)a[s[d]].pageid?w.push([a[s[d]].revisions[0]["*"],m.indexOf(a[s[d]].title)]):(alert(t.getLocalMsg("error_missing_dict")+a[s[d]].title),location.href=e.util.getUrl(null,{variant:e.config.get("wgContentLanguage")}));if(!w.length)returnn.removeSpinner("var-spinner"),void0;for(w.sort(function(e,n){returne[1]-n[1]}),d=0;w.length>d;d+=1){r=w[d][0],g=r.split("\n");for(cing)h=/^\*\s*(\S[^:]*?)\s*:\s*([\S].*?)\s*(?:\/\/.*?)?$/.exec(g[c]),h&&(t.dictionary[h[1]]=h[2])}if(_=t.settings.local_dic_id,_&&(_=_[t.lang]),u=_?document.getElementById(_):null){r=u.innerHTML,g=r.split("\n");for(ding)h=/(?:^|<ul>)<li>\s*(\S[^:]*?)(?:\s|&#160;|&nbsp;)*:\s*([\S].*?)\s*(?:\/\/.*?)?<\/li>(?:$|<\/ul>)/i.exec(g[d]),h&&(t.dictionary[h[1]]=h[2])}e.cookie.set(t.cookie,t.lang,{expires:604800,path:"/",secure:t.secure}),v=!1,l=t.conv_text_from_dic(document.title,v),l&&(document.title=l),t.conv_node_from_dic(t.$target[0]),f=t.settings.variants_list;for(pinf)f[p]!==null&&n("#ca-conv-"+p).toggleClass("selected",p===t.lang&&y==="vector");t.settings.show_menu_title&&n("#p-variants-js").find("span").text(f[t.lang]).attr("class","flag-"+t.lang),n("#ca-conv-show-hide-changes").toggle(t.lang!==e.config.get("wgContentLanguage")),t.mustReload=!0,n.removeSpinner("var-spinner")},t.startConversion=function(i){varo,a,s,r,g,c,l;if(t.lang=i,t.regClass=RegExp("(?:\\s|^)(?:v-"+t.lang+"|diff-(?:context|deletedline|addedline)|"+t.settings.no_conversion_class+")(?:\\s|$)"),t.regTypoChanges=[],r=t.settings.typo_changes,r&&(r=r[t.lang]),r)if(r.constructor===Array)for(o=0;r.length>o;o+=1)g=r[o],g.length===2&&g[1]!==null&&(typeofg[0]=="string"&&(g[0]=RegExp(e.util.escapeRegExp(g[0]),"g")),t.regTypoChanges.push(g));elseif(r.constructor===Object)for(oinr)if(r.hasOwnProperty&&r[o]!==null)try{a=RegExp(e.util.escapeRegExp(o),"g"),t.regTypoChanges.push([a,r[o]])}catch(p){alert(t.getLocalMsg("error_typo_processing")+o+": "+r[o]+".\n\n"+p.message)}returni===e.config.get("wgContentLanguage")?!1:(n("#p-variants-js").injectSpinner({id:"var-spinner"}),s=t.settings.global_dic_page[t.lang],typeofs=="object"?(c=s.api,typeofc=="object"&&c.length===2&&(c=t.secure?c[1]:c[0]),s=s.pages||s.page,l=c===e.config.get("wgServer")+e.util.wikiScript("api")?"json":"jsonp"):(c=e.util.wikiScript("api"),l="json"),n.ajax({url:c,dataType:l,data:{format:"json",action:"query",titles:s,prop:"revisions",rvprop:"content",indexpageids:"1"},success:t.conv_callback}),void0)},t.isAllowed=function(){varn=t.settings.ns_list,i="*"===n||n[e.config.get("wgNamespaceNumber")],o=t.settings.local_dic_id,a=o[e.config.get("wgContentLanguage")]?document.getElementById(o[e.config.get("wgContentLanguage")]):!1;switch(t.settings.selection_mode){case"AND":if(!i||!a)return!1;break;case"OR":if(!i&&!a)return!1}return!0},t.load=function(){t.settings={msg:{error_missing_dict:"The following dictionary was not found:\n",error_missing_dict_name:"It is necessary to define the page name of the dictionary for ",error_word_processing:"Error has occurred while processing the following word:\n",error_typo_processing:"Error has occurred while processing the following typographic change:\n",help_page_link:"Open help page",show_changes_link:"Show changes",hide_changes_link:"Hide changes",menu_title:"Variants"},word_chars:"a-zA-Z'-",typo_changes:{},variants_list:{},ns_list:{0:!0},local_dic_id:"modernization",no_conversion_class:"no-conversion",global_dic_page:"Project:Dictionary",help_page:"Project:Language Converter",show_changes:!1,show_menu_title:!0,selection_mode:"AND",max_seq:3},n.extend(!0,t.settings,t.config),t.isAllowed()&&(t.secure=location.protocol==="https:",t.$target=n("#content"),t.$target.length||(t.$target=n("#mw-content-text")),t.lang=t.get_preferred_variant(),e.cookie.set(t.cookie,t.lang,{expires:604800,path:"/",secure:t.secure}),t.render_navigation(),t.startConversion(t.lang))},n.when(e.loader.using(["mediawiki.util","mediawiki.cookie","jquery.spinner"]),n.ready).then(function(){t.load(),self.gadget_typographie&&!self.gadget_mod2&&t.conv_typo_document()})}(mediaWiki,jQuery,window.LanguageConverter);
 // </nowiki>

AltStyle によって変換されたページ (->オリジナル) /