משתמש:Bharel/סקריפטים/64-new-min.js

מתוך ויקיפדיה, האנציקלופדיה החופשית

הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
importStylesheet("משתמש:Bharel/סקריפטים/64-new.css");const a=function(){"use strict";function h(a){window.localStorage.removeItem(f+a),delete g[a]}function i(a){return $.ajax({url:mw.util.wikiScript(),data:{action:"raw",title:c[a]},dataType:"json"})}const a={},b=a.SettingTypes={NORMAL:"NORMAL",ANONYMOUS:"ANONYMOUS",GENERAL:"GENERAL"},c={[b.NORMAL]:"משתמש:"+mw.config.get("wgUserName")+"/סקריפט 64/UserSettings.js",[b.ANONYMOUS]:"משתמש:"+mw.config.get("wgUserName")+"/סקריפט 64/AnonSettings.js",[b.GENERAL]:"משתמש:"+mw.config.get("wgUserName")+"/סקריפט 64/GeneralSettings.js"},d={[b.NORMAL]:"משתמש:Bharel/סקריפט 64/DefaultUserSettings.js",[b.ANONYMOUS]:"משתמש:Bharel/סקריפט 64/DefaultAnonSettings.js",[b.GENERAL]:"משתמש:Bharel/סקריפט 64/DefaultGeneralSettings.js"},e="משתמש:Bharel/סקריפט 64/AllTemplates.js",f=mw.config.get("wgUserName")+"Script64",g={};return a.handlers=[],a.setSettings=function(a,b){let d=new mw.Api({ajax:{dataType:"json"}});return d.postWithToken("csrf",{action:"edit",title:c[a],summary:"Script 64 - Set settings",text:JSON.stringify(b)}).done(()=>{h(a)})},a.getSettings=function(b){return new Promise((c,e)=>{if(g[b])return c(g[b]);const h=window.localStorage.getItem(f+b);return h?c(g[b]=JSON.parse(h)):void i(b).done(a=>{window.localStorage.setItem(f+b,JSON.stringify(a)),g[b]=a,c(a)}).fail(f=>{if(404!=f.status)throw f;$.ajax({url:mw.util.wikiScript(),data:{action:"raw",title:d[b]},dataType:"json"}).done(d=>{a.setSettings(b,d),c(d)}).fail(a=>e(a))})})},a.withSettingsByName=function(c,d){return a.withSettings(mw.util.isIPAddress(c)?b.ANONYMOUS:b.NORMAL,d)},a.withSettings=function(b,c){return a.getSettings(b).then(c)},a.withAvailableTemplates=function(a){return $.ajax({url:mw.util.wikiScript(),data:{action:"raw",title:e},dataType:"json",cache:!0}).done(a).fail(a=>{throw a})},a.withSeparateAvailableTemplates=function(c){return a.withAvailableTemplates(a=>{const d={},e={};for(const[f,g]of Object.entries(a)){const a=d[f]=[],b=e[f]=[];for(const c of g)switch(c.anon){case!0:a.push(c);break;case!1:b.push(c);break;default:a.push(c),b.push(c)}}c({[b.ANONYMOUS]:d,[b.NORMAL]:e})})},a.createLinksElement=function(c,d){const e=document.createElement("span"),f=()=>{function f(b){let c=document.createElement("a");c.href="#",c.insertAdjacentText("beforeend",b.name),c.warningTemplate=b,a.appendChild(c)}const a=document.createDocumentFragment(),b=document.createTextNode(" | ");e.addEventListener("click",a=>{for(let b=a.target;b!==a.currentTarget;b=b.parentNode)if(b.warningTemplate)return a.stopPropagation(),a.preventDefault(),this.activateWarning(c,b.warningTemplate)}),a.appendChild(document.createTextNode("(")),f(d[0]);for(let g=1;g<d.length;g++)a.appendChild(b.cloneNode()),f(d[g]);a.appendChild(document.createTextNode(")")),e.appendChild(a)};return a.withSettings(b.GENERAL,a=>{if(!a.hideOptions[void 0===window.orientation?"desktop":"mobile"])return f();const b=document.createElement("button");b.insertAdjacentText("beforeend","הצג תבניות"),b.addEventListener("click",()=>window.setTimeout(()=>{e.removeChild(b),f()},400)),e.appendChild(b)}),e},a.activateWarning=function(a,b){let c=b.template;const d=mw.config.get("wgPageName").replace(/_/g," "),e=([6,14].includes(mw.config.get("wgNamespaceNumber"))?":":"")+d;if(b.noPage||(c+="|"+e),b.askExtra)if(b.askExtra.prompt){const a=prompt(b.askExtra.prompt);null!==a&&(c+=b.askExtra.param+a.trim())}else b.askExtra.confirm&&confirm(b.askExtra.confirm)&&(c+=b.askExtra.param);let f="{{"+c+"}} ~~"+"~~\n";b.title?f="\n=="+b.title+"==\n"+f:b.noTitle||(f="\n=="+(b.noLinkTitle?d:"[["+e+"]]")+"==\n"+f);const g=new this.pageHandler("שיחת משתמש:"+a);b.prepend?g.prepend(f,b.template):g.append(f,b.template),void 0!==b.watch&&(g.watch=b.watch),g.submit().then(()=>mw.notify(' תבנית "'+b.template+'" נרשמה בשיחת משתמש:'+a)).catch(a=>alert("Error saving: "+String(a)))},a.pageHandler=class a{constructor(a){this.action="edit",this.title=a,this.summary=[],this.format="json",this.token=mw.user.tokens.get("csrfToken")}append(a,b){return this.appendtext=(this.appendtext?this.appendtext:"")+a,b&&this.summary.push(b),this}prepend(a,b){return this.prependtext=(this.prependtext?this.prependtext:"")+a,b&&this.summary.push(b),this}get watch(){if(void 0!==this.watchlist)return"watch"===this.watchlist}set watch(a){this.watchlist=a?"watch":"unwatch"}submit(){return this.summary=this.summary.join(", "),new Promise((a,b)=>{$.post(mw.util.wikiScript("api"),this,c=>{if(c.error)return b(c.error);if(c.edit&&"Success"==c.edit.result)return a(c);throw c}).fail(a=>{throw a})})}},a.SettingsDialog={DIALOG_BOX_TEMPLATE:['<div id="setting64" title="הגדרות סקריפט 64">','<div id="setting64Tabs">',"<ul>",'<li><a href="#setting64AnonTab">אנונימים</a></li>','<li><a href="#setting64NormalTab">משתמשים</a></li>',"</ul>",'<div id="setting64AnonTab"></div>','<div id="setting64NormalTab"></div>',"</div>",'<div id="setting64General">',"הסתרת תבניות:",'<ul id="setting64HideOptions">',"<li>",'<input type=checkbox id="setting64HideDesktop" />','<label for="setting64HideDesktop">במחשב נייח</label>',"</li>","<li>",'<input type=checkbox id="setting64HideMobile" />','<label for="setting64HideMobile">בנייד</label>',"</li>","</ul>",'<div id="setting64AdvancedSettings" style="display: none">','<button id="setting64AddManual">הוספת תבנית בצורה ידנית',"</button></br>",'<button id="setting64PurgeCache">נקה מטמון</button></br>',"</div>",'<input type=checkbox id="setting64ShowAdvanced" />','<label for="setting64ShowAdvanced">הצג הגדרות מתקדמות</label>',"</div>","</div>"].join(""),openDialog:function(){mw.loader.using(["jquery.ui"]).done(()=>{return this.$dialogBox?void this.$dialogBox.dialog("open"):void this.createDialog().dialog("open")})},newTemplateDialog:function(){const a=$(['<div id="setting64NewTemplate">',"<form>","<span>כל השדות חובה.</span></br>",'<label>שם: <input type="text" id="setting64NameField">',"</label><br>",'<label>תבנית: <input type"text" id="setting64TemplateField">',"</label><br>",'הוסף לתבניות <select id="setting64LocationField"></select>.<br>',"הוסף עבור:</br>",'<input type="radio" name="setting64CategoryRadio" ','value="anon">אנונימים</br>','<input type="radio" name="setting64CategoryRadio" ','value="normal">משתמשים</br>','<input type="radio" name="setting64CategoryRadio" ','value="both" checked="checked">שניהם<br>','<input type="submit" value="הוספה" tabindex="-1" ','style="position:absolute; top:-1000px">',"</form>","</div>"].join("")),c=a[0].querySelector("#setting64LocationField");[["אזהרה","rollbackWarnings"],["מחיקה","deletionWarnings"],["חסימה","blockWarnings"]].forEach(([a,b])=>{const d=document.createElement("option");d.warningType=b,d.text=a,c.appendChild(d)});const d=a[0].firstChild,e=()=>{const e={};if(e.name=document.getElementById("setting64NameField").value,e.template=document.getElementById("setting64TemplateField").value,0===e.name.length||0===e.template.length)return void d.firstChild.classList.add("ui-state-error");e.description="הוספת תבנית "+e.name;const f=d.querySelector('input[name="setting64CategoryRadio"]:checked').value,g=c.options[c.selectedIndex].warningType;switch(f){case"anon":this.sortables[b.ANONYMOUS][g].appendTemplate(e);break;case"normal":this.sortables[b.NORMAL][g].appendTemplate(e);break;case"both":this.sortables[b.ANONYMOUS][g].appendTemplate(e),this.sortables[b.NORMAL][g].appendTemplate(e);break;default:throw"Error: Unknown radio selected"}a.dialog("close"),a.empty()};d.addEventListener("submit",a=>{a.preventDefault(),e()}),a.dialog({autoOpen:!0,height:300,width:250,modal:!0,buttons:{"הוסף":e,"סגור":()=>{a.dialog("close"),a.empty()}}})},WarningSortable:class a{constructor(a,b){const c=this.mainNode=document.createDocumentFragment(),d=this.sortable_=document.createElement("ul"),e=this.selectElement_=document.createElement("select"),f=this.templateNames_=new Set,g=document.createElement("span");d.className="script-64-sortable",g.className="ui-icon ui-icon-plus",d.addEventListener("click",a=>{for(let b=a.target;b!==a.currentTarget;b=b.parentNode)if("ui-icon ui-icon-close"===b.className){const c=b.parentNode;return a.stopPropagation(),a.preventDefault(),d.removeChild(c),f.delete(c.warningTemplate.name),void this.appendAvailableTemplate(c.warningTemplate)}}),a.forEach(this.appendTemplate,this),b.forEach(this.appendAvailableTemplate,this);const h=$(d);g.addEventListener("click",()=>{const a=e.options[e.selectedIndex];f.delete(a.warningTemplate.name),this.appendTemplate(a.warningTemplate),e.removeChild(a),h.sortable()}),h.sortable(),h.disableSelection(),c.appendChild(d),c.appendChild(e),c.appendChild(g)}appendAvailableTemplate(a){if(!this.templateNames_.has(a.name)){const b=document.createElement("option");b.text=a.name,b.warningTemplate=a,this.selectElement_.appendChild(b),this.templateNames_.add(a.name)}}appendTemplate(a){if(!this.templateNames_.has(a.name)){const b=document.createElement("li"),c=document.createElement("span"),d=document.createElement("span");c.className="ui-icon ui-icon-close",d.className="ui-icon ui-icon-arrowthick-2-n-s",b.className="ui-state-default",b.warningTemplate=a,b.appendChild(c),b.appendChild(d),b.insertAdjacentText("beforeend",a.name),this.sortable_.appendChild(b),this.templateNames_.add(a.name)}}get templates(){return[...this.sortable_.children].map(a=>a.warningTemplate)}},createDialog:function(){const c=this.$dialogBox=$(this.DIALOG_BOX_TEMPLATE);this.sortables={};const d=(a,b)=>{const c=document.createDocumentFragment(),d=document.createElement("div"),e={};return d.className="script-64-warnings",d.appendChild(document.createElement("h2")),[["תבניות לאזהרה","rollbackWarnings"],["תבניות למחיקת דפים","deletionWarnings"],["תבניות לחסימה","blockWarnings"]].forEach(([f,g])=>{const h=new this.WarningSortable(a[g],b[g]);e[g]=h;const i=d.cloneNode(!0);i.firstChild.textContent=f,i.dataset.settingName=g,i.appendChild(h.mainNode),c.appendChild(i)}),[c,e]},e=c.find("#setting64AnonTab"),f=c.find("#setting64NormalTab"),g=(c=false)=>{function g(a){const b=[].concat(...Object.values(a)),c={};for(const d of Object.keys(a))c[d]=[...b];return c}a.withSeparateAvailableTemplates(h=>{a.withSettings(b.ANONYMOUS,a=>{let f,i;[f,i]=c?d(a,g(h[b.ANONYMOUS])):d(a,h[b.ANONYMOUS]),e.append(f),this.sortables[b.ANONYMOUS]=i}),a.withSettings(b.NORMAL,a=>{let e,i;[e,i]=c?d(a,g(h[b.NORMAL])):d(a,h[b.NORMAL]),f.append(e),this.sortables[b.NORMAL]=i})})};return g(),c.find("#setting64ShowAdvanced").change(a=>{const b=a.currentTarget.checked;e.empty(),f.empty(),g(b),b?c.find("#setting64AdvancedSettings").css("display","block"):c.find("#setting64AdvancedSettings").css("display","none")}),a.withSettings(b.GENERAL,a=>{c.find("#setting64HideDesktop").prop("checked",a.hideOptions.desktop),c.find("#setting64HideMobile").prop("checked",a.hideOptions.mobile)}),c.find("#setting64AddManual").click(this.newTemplateDialog.bind(this)),c.find("#setting64PurgeCache").click(()=>{Object.values(b).forEach(h,this.Manager),console.log("Purged cache.")}),c.dialog({autoOpen:!1,height:400,width:350,modal:!0,buttons:{"שמירה":()=>{this.saveBox().done(()=>mw.notify("הגדרות סקריפט 64 נשמרו בהצלחה.")),c.dialog("close")},"סגירה":()=>c.dialog("close")}}),c.find("#setting64Tabs").tabs(),c},saveBox:function(){function c(a){const b={};for(const[c,d]of Object.entries(a))b[c]=d.templates;return b}const d={hideOptions:{desktop:document.getElementById("setting64HideDesktop").checked,mobile:document.getElementById("setting64HideMobile").checked}};return $.when(a.setSettings(b.ANONYMOUS,c(this.sortables[b.ANONYMOUS])),a.setSettings(b.NORMAL,c(this.sortables[b.NORMAL])),a.setSettings(b.GENERAL,d))}},a.loadManager=function(){this.mainElement=document.getElementById("mw-content-text"),mw.util.addPortletLink("p-tb","#","הגדרות סקריפט 64").onclick=this.SettingsDialog.openDialog.bind(this.SettingsDialog);for(const a of this.handlers)if(a(this))break},a}();a.handlers.push(function(a){"use strict";function b(a,b){return b.parentNode.insertBefore(a,b.nextSibling)}if("Block"===mw.config.get("wgCanonicalSpecialPageName")){const c=a.mainElement.getElementsByTagName("a")[0],d=c.firstChild.nodeValue,e=document.createTextNode(" ");return b(e,c.parentNode),a.withSettingsByName(d,c=>{b(a.createLinksElement(d,c.blockWarnings),e)}),!0}}),a.handlers.push(function(a){"use strict";const b=document.getElementById("mw-diff-ntitle2");if(null!==b){const c=b.getElementsByTagName("bdi")[0].firstChild.nodeValue,d=document.createElement("p");return a.withSettingsByName(c,e=>{d.appendChild(a.createLinksElement(c,e.rollbackWarnings)),b.appendChild(d)}),!0}}),a.handlers.push(function(a){"use strict";function e(a,b){return b.parentNode.insertBefore(a,b.nextSibling)}function k(a){a&&a.query&&a.query.blocks&&a.query.blocks&&a.query.blocks.length&&(i.className="script-64-activated-indicator",i.title="נחסם על ידי "+decodeURIComponent(a.query.blocks[0].by))}if("rollback"===mw.config.get("wgAction")){const b=a.mainElement.getElementsByTagName("bdi")[0];if(b){const c=b.parentNode.nextElementSibling,d=b.firstChild.nodeValue;console.assert("mw-usertoollinks"==c.className,c.className);const f=document.createDocumentFragment();f.appendChild(document.createTextNode(" ("));const g=document.createElement("span");g.id="script-64-status-span";const h=document.createElement("span");h.textContent="הוזהר",g.appendChild(h),g.insertAdjacentText("beforeend"," ");const i=document.createElement("span");i.textContent="חסום",g.appendChild(i),f.appendChild(g),f.appendChild(document.createTextNode(") ")),a.withSettingsByName(d,b=>{f.appendChild(a.createLinksElement(d,b.rollbackWarnings)),e(f,c)});const j=new mw.Api;return mw.util.isIPAddress(d)?j.get({list:"blocks",bkip:d}).done(k):j.get({list:"blocks",bkusers:d}).done(k),j.get({action:"query",titles:"שיחת משתמש:"+d,prop:"revisions",indexpageids:!0,rvprop:["user","timestamp","comment"],rvlimit:5,format:"json"}).done(b=>{const c=b.query.pageids[0];"-1"!==c&&a.withAvailableTemplates(a=>{const d=b.query.pages[c].revisions,e=mw.now()-2592e6,f=[].concat(...Object.values(a)),g=new Set(f.map(a=>a.template));for(const i of d){const a=new Date(i.timestamp);if(a<e)return;if(g.has(i.comment))return h.title=`הוזהר על ידי ${i.user} `+`בתאריך ${a.toLocaleString()}.`,void(h.className="script-64-activated-indicator")}})}),!0}}}),a.handlers.push(function(a){"use strict";if("delete"===mw.config.get("wgAction")&&mw.config.get("wgUserGroups").includes("sysop")&&!document.getElementById("deleteconfirm"))return $.getJSON(mw.util.wikiScript("api"),{action:"query",list:"deletedrevs",drlimit:20,titles:mw.config.get("wgPageName"),drprop:"user",format:"json"},function(b){function e(a){function b(a,b){const c=document.createElement("a");return c.setAttribute("href",a),c.textContent=b,c}const c=document.createDocumentFragment();return c.appendChild(b(mw.util.getUrl("User:"+a),a)),c.appendChild(document.createTextNode(" (")),c.appendChild(b(mw.util.getUrl("User Talk:"+a),"שיחה")),c.appendChild(document.createTextNode(" | ")),c.appendChild(b(mw.util.getUrl("Special:Contributions/"+a),"תרומות")),c.appendChild(document.createTextNode(" | ")),c.appendChild(b(mw.util.getUrl("Special:Block/"+a),"חסימה")),c.appendChild(document.createTextNode(" ) ")),c}const c=new Set;if(!(b&&b.query&&b.query.deletedrevs))throw"No deleted revisions..?";b.query.deletedrevs.forEach(a=>a.revisions.forEach(a=>c.add(a.user)));const d=document.createElement("p");d.insertAdjacentText("beforeend",`את הדף ${mw.config.get("wgPageName")} ערכו העורכים הבאים:`),c.forEach(b=>a.withSettingsByName(b,c=>{const f=document.createElement("p");f.appendChild(e(b)),f.appendChild(a.createLinksElement(b,c.deletionWarnings)),d.appendChild(f)})),a.mainElement.appendChild(d)}),!0}),a.loadPolyfills=function(){"use strict";const b=Function.bind.call(Function.call,Array.prototype.reduce),c=Function.bind.call(Function.call,Object.prototype.propertyIsEnumerable),d=Function.bind.call(Function.call,Array.prototype.concat),e=Reflect.ownKeys;return Object.values||(Object.values=function(f){return b(e(f),(a,b)=>d(a,"string"==typeof b&&c(f,b)?[f[b]]:[]),[])}),Object.entries||(Object.entries=function(f){return b(e(f),(a,b)=>d(a,"string"==typeof b&&c(f,b)?[[b,f[b]]]:[]),[])}),Array.prototype.includes||Object.defineProperty(Array.prototype,"includes",{value:function(a,b){if(null==this)throw new TypeError('"this" is null or not defined');var c=Object(this),d=c.length>>>0;if(0===d)return!1;for(var e=0|b,f=Math.max(e>=0?e:d-Math.abs(e),0);f<d;){if(c[f]===a)return!0;f++}return!1}}),$.when()},a.loadPolyfills().done(()=>{"use strict";["loaded","complete","interactive"].includes(document.readyState)?a.loadManager():document.addEventListener("DOMContentLoaded",a.loadManager.bind(a))});