User:Tgr/summary.js
A Wikipédiából, a szabad lexikonból.
Megjegyzés: A beállítások elmentése után frissítened kell a böngésződ gyorsítótárát, hogy a változások érvénybe lépjenek. Mozilla / Firefox / Safari: tartsd lenyomva a Shift gombot és kattints a Reload / Frissítés gombra az eszköztáron, vagy használd a Ctrl–F5 billentyűkombinációt (Apple Mac-en Cmd–Shift–R); Internet Explorer: tartsd nyomva a Ctrl-t, és kattints a Reload / Frissítés gombra, vagy nyomj Ctrl–F5-öt; Konqueror: egyszerűen csak kattints a Reload / Frissítés gombra (vagy Ctrl–R vagy F5); Opera felhasználóknak teljesen ki kell üríteniük a gyorsítótárat a Tools→Preferences menüben.
/* automatically set default value for summary fields * (elements with wpSummary or wpReason id) * (except for new section summary) * install a button to set/change default value * TODO: touched flag for summary field/minor edit checkbox * to avoid overwriting manually specified values when hitting back button */ function readSummaryCookie() { var cookieText; var cookiePos = document.cookie.indexOf('autosummary='); if(cookiePos!=-1) { var results = document.cookie.match('autosummary=(.*?)(;|$)'); if(results) cookieText = unescape(results[1]); } else cookieText = ''; return cookieText; } function writeSummaryCookie(text) { if(text) { document.cookie = 'autosummary='+escape(text); } else { document.cookie = 'autosummary=; expires=Thu, 01-Jan-1970 00:00:01 GMT;'; // delete cookie } } function autoSummaryInstall() { if(!document.getElementById || !document.createElement) return; // DOM check var summary = document.getElementById('wpSummary'); // edit summary if(!summary) summary = document.getElementById('wpReason'); // admin del/block/etc. summary if(!summary) return; // edit mode check if(/§ion=new/.test(window.location.href)) return; var summaryText = readSummaryCookie(); // set summary text if(summaryText) { if(summaryText.match(/^\(m\)/)) { // mark edit as minor if(document.getElementById("wpMinoredit")) document.getElementById("wpMinoredit").checked = true; summaryText = summaryText.replace(/^\(m\) */, ''); } if(summary.value.match(/^(\/\*.*\*\/)? *$/)) summary.value += summaryText; // avoid overwriting summary when using back button } // create button var autoSummaryButton = document.createElement('a'); autoSummaryButton.id = 'autosummary'; if(summaryText) autoSummaryButton.className = 'internal'; else autoSummaryButton.className = 'new'; autoSummaryButton.href = 'javascript:autoSummary()'; autoSummaryButton.appendChild(document.createTextNode('[auto]')); var br = summary.nextSibling; br.parentNode.insertBefore(autoSummaryButton, br); } function autoSummary() { var summaryText = readSummaryCookie(); var r = prompt('Összefoglaló szövege:', summaryText); if(r!=null) { // user pressed Ok if(r) { if(r.match(/^\(m\)/)) { // mark edit as minor if(document.getElementById("wpMinoredit")) document.getElementById("wpMinoredit").checked = true; r = r.replace(/^\(m\) */, ''); } var summary = document.getElementById('wpSummary'); if(!summary) summary = document.getElementById('wpReason'); if(summary.value.match(/^(\/\*.*\*\/)? *$/)) summary.value += r; } writeSummaryCookie(r); } } addLoadEvent(autoSummaryInstall);