User:Connel MacKenzie/custom.js

/* WT:PREFS-specific cookie handling 1/25/2007

Warning: The numbers associated with each preference must not be changed. (The cookie that stores preferences is written as a sequence of preference values without the corresponding preference names.) */

var prefs = { WiktionaryUseJSPreferences                    : 1, WiktionaryPreferencesHideSister               : 2, WiktionaryPreferencesSmallRC                  : 3, WiktionaryPreferencesHideTransitivity         : 4, WiktionaryPreferencesHideRankings             : 5, WiktionaryPreferencesHideIBParens             : 6, WiktionaryPreferencesHideLinesBetweenLanguages : 7, WiktionaryPreferencesHideTranslations         : 8, WiktionaryPreferencesBoxedInflections         : 9, WiktionaryPreferencesIndentSeeAlso            : 10, WiktionaryPreferencesHideSiteNotice           : 11, WiktionaryPreferencesCiteTab                  : 12, WiktionaryPreferencesSpellCheck               : 13, WiktionaryPreferencesTime                     : 14, WiktionaryPreferencesPopUps                   : 15, WiktionaryPreferencesKeyPad                   : 16, WiktPrefConnelReformat                        : 17, WiktPrefPatrol                                : 18, WiktPrefDelCmnt                               : 19, WiktPrefDiff                                  : 20, /* disabled until rewritten */ WiktMakeRedLinksBlack                         : 21, /* was WiktIrc a very long time ago… */ WiktAjaxTransLinks                            : 22, WiktAddStructure                              : 23, WiktHideLogo                                  : 24, WiktFormOfPlain                               : 25, WiktFormOfItalicQualifier                     : 26, WiktFormOfItalicLemma                         : 27, WiktFormOfItalicQualifierBoldLemma            : 28, WiktEnMentionItalics                          : 29, /* no longer used */ WiktEnMentionDoubleQuotes                     : 30, /* no longer used */ WiktEnMentionSingleQuotes                     : 31, /* no longer used */ WiktLatnMentionBold                           : 32, WiktMentionGlossSingleQuotes                  : 33, WiktionaryPreferencesHideQualifierParens      : 34, WiktionaryPreferencesItalicParens             : 35, WiktShowLinguistLabels                        : 36, /* no longer used */ WiktHideTrGlossParens                         : 37, WiktHideAllParens                             : 38, WiktHideGlossParens                           : 39, WiktPlainTransliterations                     : 40, WiktIrc2                                      : 41, WiktFilterContributions                       : 42, WiktCIDRRangeContribs                         : 43, WiktSidebarTranslation                        : 44, WiktQuickLookup                               : 45, WiktBlockedNotice                             : 46, WiktAddProminentInterwikis                    : 47, /* This is just to allow people to test easily */ WiktFloatNavToggleLeft                        : 48, WiktAspellPrototype                           : 49, /* Removed as the aspell server is down */ WiktPreviewRightTOCs                          : 50, WiktAccelerateFormCreation                    : 51, WiktAssistedEditing                           : 52, WiktionaryPreferencesEditTools : 53, /* hide EditTools under search field */ WiktNearbyPages                               : 54  /* Show links to previous and next pages */ };

/* Warning: The numbers associated with each preference must not be changed. (The cookie that stores preferences is written as a sequence of preference values without the corresponding preference names.) */

var tempC = '';

function wiktGetPrefCookie(wiktPrefName) { //When we have a few hundred prefs, I’ll have to do this in binary, instead of text "0" & "1" tempC = getCookie('WiktPrefs'); var prefa = tempC.split("-") ; var versi = prefa[0]; //if (versi == 0.1 ) { if (getCookie(wiktPrefName) == 'true') return 'true'; if (prefa[prefs[wiktPrefName]]) { if (prefa[prefs[wiktPrefName]] == 1) { return 'true'; } else return 'false'; } else { return getCookie(wiktPrefName); } //} }

function wiktSetPrefCookie(wiktPrefName, wiktValue) { tempC = getCookie('WiktPrefs'); var prefa = tempC.split("-"); var versi = "0.1" + "-"; var wiktVal2 = 0; if (wiktValue == 'true') wiktVal2 = 1;

if (prefs[wiktPrefName]) { prefa[prefs[wiktPrefName]] = wiktVal2; } else { setCookie(wiktPrefName, wiktValue); return; }

for (var i in prefs) { if ( prefa[prefs[i]] ) { if ( wiktPrefName == i ) { versi += wiktVal2 + "-"; mw.cookie.set(i, null); } else { if ( wiktGetPrefCookie(i) == 'true' ) { versi += "1" + "-"; } else { versi += "0" + "-"; }       mw.cookie.set(i, null); }   } else { versi += "0" + "-"; } }  setCookie('WiktPrefs', versi); return; }

/* Javascript to perform the CSS insertions */

if ( wiktGetPrefCookie('WiktionaryUseJSPreferences') == 'true' ) {

//Start by refreshing the cookies, deleting the old format cookies. wiktSetPrefCookie('WiktionaryUseJSPreferences', 'true');

// CSS Insertions if ( wiktGetPrefCookie('WiktionaryPreferencesHideSister') == 'true' ) addCSSRule('#bodyContent .sister-project','display: none;'); if ( wiktGetPrefCookie('WiktionaryPreferencesSmallRC') == 'true' ) addCSSRule('#bodyContent .minifont','font-size: 75%;'); if ( wiktGetPrefCookie('WiktionaryPreferencesHideTransitivity') == 'true' ) addCSSRule('#transitivity','display:none'); if ( wiktGetPrefCookie('WiktionaryPreferencesHideRankings') == 'true' ) addCSSRule('#rank','display: none'); if ( wiktGetPrefCookie('WiktionaryPreferencesHideIBParens') == 'true' ) addCSSRule('#bodyContent .ib-brac','display:none'); if ( wiktGetPrefCookie('WiktionaryPreferencesHideQualifierParens') == 'true' ) addCSSRule('#bodyContent .qualifier-brac','display:none'); if ( wiktGetPrefCookie('WiktHideAllParens') == 'true' ) addCSSRule('.ib-brac, .term-tr-gloss-paren, .term-gloss-paren','display:none'); if ( wiktGetPrefCookie('WiktionaryPreferencesItalicParens') == 'true' ) addCSSRule('.ib-brac, .ib-comma, .sense-qualifier-colon','font-style: italic');

if ( wiktGetPrefCookie('WiktionaryPreferencesHideLinesBetweenLanguages') == 'true' ) addCSSRule('.ns-0 #bodyContent hr','visibility: hidden');

if ( wiktGetPrefCookie('WiktionaryPreferencesHideTranslations') == 'true' ) addCSSRule('#bodyContent .translations','display:none'); if ( wiktGetPrefCookie('WiktionaryPreferencesBoxedInflections') == 'true' ) { addCSSRule('#bodyContent .infl-inline','display:none'); addCSSRule('#bodyContent .infl-table','display:inline'); }  if ( wiktGetPrefCookie('WiktionaryPreferencesIndentSeeAlso') == 'true' ) addCSSRule('#bodyContent .disambig-see-also, #bodyContent .disambig-see-also-2','text-indent: 4em');

if ( wiktGetPrefCookie('WiktionaryPreferencesHideSiteNotice') == 'true' ) addCSSRule('#siteNotice', 'display: none;'); if ( wiktGetPrefCookie('WiktHideLogo') == 'true' ){ addCSSRule('#p-logo','display: none;'); addCSSRule('#column-one','padding-top: 0;'); }

if ( wiktGetPrefCookie('WiktFormOfPlain') == 'true' ) addCSSRule('.use-with-mention .mention','font-weight: normal !important;'); if ( wiktGetPrefCookie('WiktFormOfItalicQualifier') == 'true' ){ addCSSRule('.use-with-mention','font-style: italic;'); addCSSRule('.use-with-mention .mention','font-weight: normal !important;'); } if ( wiktGetPrefCookie('WiktFormOfItalicLemma') == 'true' ) addCSSRule('.use-with-mention .mention','font-style: italic !important; font-weight: normal !important;'); if ( wiktGetPrefCookie('WiktFormOfItalicQualifierBoldLemma') == 'true' ) addCSSRule('.use-with-mention','font-style: italic;'); if ( wiktGetPrefCookie('WiktEnMentionItalics') == 'true' ) addCSSRule('.en-mention','font-style: italic; font-weight: normal !important;'); if ( wiktGetPrefCookie('WiktEnMentionDoubleQuotes') == 'true' ) { addCSSRule('.en-mention','font-weight: normal !important; '); addCSSRule('.en-mention-double-quote','display: inline !important;'); } if ( wiktGetPrefCookie('WiktEnMentionSingleQuotes') == 'true' ){ addCSSRule('.en-mention','font-weight: normal !important;'); addCSSRule('.en-mention-single-quote','display: inline !important;'); } if ( wiktGetPrefCookie('WiktLatnMentionBold') == 'true' ) addCSSRule('.mention-Latn','font-style: normal !important; font-weight: bold;');

if ( wiktGetPrefCookie('WiktMentionGlossSingleQuotes') == 'true' ){ addCSSRule('.mention-gloss-double-quote','display: none !important;'); addCSSRule('.mention-gloss-single-quote','display: inline !important;'); } if ( wiktGetPrefCookie('WiktHideTrGlossParens') == 'true' ) addCSSRule('.term-tr-gloss-paren, .term-tr-paren, .term-gloss-paren','display: none'); if ( wiktGetPrefCookie('WiktHideGlossParens') == 'true' ){ addCSSRule('.mention-tr-gloss-separator-paren','display:inline !important'); addCSSRule('.mention-gloss-paren, .mention-tr-gloss-separator-comma','display:none'); } if ( wiktGetPrefCookie('WiktPlainTransliterations') == 'true' ) addCSSRule('.mention-tr-paren, .mention-tr','font-style:normal !important');

if ( wiktGetPrefCookie('WiktShowLinguistLabels') == 'true' ){ addCSSRule('.label-layman','display: none'); addCSSRule('.label-linguist','display: inline !important;'); }

if ( wiktGetPrefCookie('WiktFloatNavToggleLeft') == 'true' ){ addCSSRule('.NavToggle','float: left !important; position: static !important; right: inherit; margin-top: 0.1em; margin-right: 5px;'); }

if ( wiktGetPrefCookie('WiktPreviewRightTOCs') == 'true' ){ addCSSRule('.ns-0 #toc','float: right; clear: right; margin-left: 7px; margin-bottom: 6px; display: inline;'); } if ( wiktGetPrefCookie ('WiktMakeRedLinksBlack') == 'true' ) addCSSRule('.inflection-table a.new', 'color: #000000;'); if ( wiktGetPrefCookie ('WiktionaryPreferencesEditTools') == 'true' ) addCSSRule('.mw-editTools', 'display: none;');

//Additional optional JavaScript insertions

if ( wiktGetPrefCookie('WiktionaryPreferencesSpellCheck') == 'true' ) importScript('User:Connel_MacKenzie/spellcheck.js');

if ( wiktGetPrefCookie('WiktionaryPreferencesTime') == 'true' ) importScript('User:Connel_MacKenzie/clock.js'); if ( wiktGetPrefCookie('WiktionaryPreferencesPopUps') == 'true' ) { importScript('User:Lupin/popups.js','en.wikipedia.org'); importScript('User:Connel_MacKenzie/mess-with-popups.js'); }

if ( wiktGetPrefCookie('WiktionaryPreferencesKeyPad') == 'true' ) importScript('User:Connel_MacKenzie/keypad.js'); if ( wiktGetPrefCookie('WiktPrefConnelReformat') == 'true' ) importScript('User:Connel_MacKenzie/reformat.js');

if ( wiktGetPrefCookie('WiktPrefPatrol') == 'true' ) importScript('User:Connel_MacKenzie/patrolled.js');

if ( wiktGetPrefCookie('WiktPrefDelCmnt') == 'true' ) importScript('User:Connel_MacKenzie/del-cmnt.js');

if ( wiktGetPrefCookie('WiktIrc2') == 'true' ) importScript('User:Connel_MacKenzie/irc.js');

if ( wiktGetPrefCookie('WiktAddStructure') == 'true' ) importScript('User:Conrad.Irwin/parser.js');

if ( wiktGetPrefCookie('WiktAjaxTransLinks') == 'true' ) importScript('User:Hippietrail/ajaxtranslinks.js');

if ( wiktGetPrefCookie('WiktCIDRRangeContribs') == 'true' ) importScript('User:TheDaveRoss/CIDR.js');

if ( wiktGetPrefCookie('WiktFilterContributions') == 'true' ) importScript('User:Hippietrail/filtercontribs.js');

if ( wiktGetPrefCookie('WiktSidebarTranslation') == 'true' ) importScript('User:Bequw/sidebartranslate.js'); if ( wiktGetPrefCookie('WiktQuickLookup') == 'true' ) importScript('User:Bequw/quickLookup.js');

if( wiktGetPrefCookie('WiktBlockedNotice') == 'true' ) importScript('User:Conrad.Irwin/isblocked.js'); if( wiktGetPrefCookie('WiktAddProminentInterwikis') == 'true' ) importScript('User:Conrad.Irwin/iwiki.js');

//if( wiktGetPrefCookie('WiktAspellPrototype') == 'true' ) // importScript('User:Conrad.Irwin/aspell.js');

if ( wiktGetPrefCookie('WiktAccelerateFormCreation') == 'true' ) { importScript('User:Conrad.Irwin/creation.js'); if (wiktGetPrefCookie('WiktionaryPreferencesPopUps') != 'true' ) { importScript('User:Lupin/autoedit.js', 'en.wikipedia.org','46637295'); } }

if ( wiktGetPrefCookie('WiktAssistedEditing') == 'true') { importScript('user:Conrad.Irwin/editor.js'); }

if ( wiktGetPrefCookie('WiktNearbyPages') == 'true' ) importScript('User:Hippietrail/nearbypages.js'); }

//array of images enWiktPrefButtons = [] ;

/*

wiktAddButton
*/ // generate buttons function wiktAddButton(cookieToToggle, speedTip) { var checkbox = document.createElement("input"); checkbox.type = 'checkbox'; checkbox.name = cookieToToggle; checkbox.onclick = function { if ( wiktGetPrefCookie(this.name) != 'true' ) { wiktSetPrefCookie(this.name, 'true'); } else { wiktSetPrefCookie(this.name, 'false'); }   }        if ( 'true' == wiktGetPrefCookie( cookieToToggle ) ) { checkbox.checked = true ; }      var isPreferencePage = document.getElementById('isPreferencePage'); isPreferencePage.appendChild( checkbox ); if ( 'true' == wiktGetPrefCookie( cookieToToggle ) ) { checkbox.checked = true ; }      var text = document.createTextNode( speedTip ); isPreferencePage.appendChild( text ); var text = document.createElement( 'br' ); isPreferencePage.appendChild( text ); return true; }

function wiktAddSeparator(wiktSepText) { var pnod = document.createElement('p'); var isPreferencePage = document.getElementById('isPreferencePage'); pnod.appendChild( document.createTextNode( wiktSepText ) ); pnod.appendChild( document.createElement( 'hr' ) ); isPreferencePage.appendChild( pnod );

}

//not used just yet function wiktAddTextBox(cookieToInput, speedTip) { var textbox = document.createElement("input"); textbox.type = 'text'; textbox.width = 10; textbox.name = cookieToInput; textbox.onchange = function { wiktSetPrefCookie(this.name, this.value); }       textbox.value = wiktGetPrefCookie( cookieToInput ); isPreferencePage.appendChild( textbox ); var text = document.createTextNode( speedTip ); isPreferencePage.appendChild( text ); return true; }

/*

CustomizePreferencesPage
*/
 * Note that this needs to be re-written as a separate tab (or two or three) that appear when wgPageName=="Special:Preferences".

function CustomizePreferencesPage { //If on Special:Preferences, add reminder link var isWmPrefsPage = document.getElementById('wpReset'); if (isWmPrefsPage) { var wiktlink = document.createElement("a"); wiktlink.setAttribut('href', '/wiki/Wiktionary:Preferences'); var wiktltxt = document.createTextNode("See also: Wiktionary-specific preferences"); wiktlink.appendChild( wiktltxt ); isWmPrefsPage.appendChild( wiktlink ); }  var isPreferencePage = document.getElementById('isPreferencePage'); if ( !isPreferencePage ) return;

//OK, so now we know we are on  //the Set EnglishWiktionary-specific Preferences page (or impersonation thereof)

// Hide the "noscript" div and display the "hasscript" one var noscript = document.getElementById('wtprefs.noscript'); var hasscript = document.getElementById('wtprefs.hasscript');

if (noscript != null && hasscript != null) { noscript.style.display = 'none'; hasscript.style.display = 'block'; }

// http://tools.wikimedia.de/~cmackenzie/make_buttons.html // crop image to 21 pixels vertical, whatever horizontal.

//TODO: gray out all other choices if this is not yet checked!!! wiktAddButton( 'WiktionaryUseJSPreferences', 'Use the preferences set on this page');

wiktAddSeparator('>IMPORTANT – If the above box is unchecked, EVERYTHING on this page is turned off');

wiktAddSeparator('Preferences that change the display of the interface. [Probably only work with the Monobook skin]');

// Hide special characters for edit field wiktAddButton( 'WiktionaryPreferencesEditTools', 'Hide the special character input beneath the edit field.' );

// Allow special characters in [Search] input wiktAddButton( 'WiktionaryPreferencesKeyPad', 'Show a special character input (like the one beneath the edit field) for the search field.');

wiktAddButton( 'WiktionaryPreferencesHideSiteNotice', 'Hide the display of site-wide notices at the top of the screen.'); wiktAddButton( 'WiktHideLogo', 'Hide the logo in the upper left corner.');

// Andrew's clock wiktAddButton( 'WiktionaryPreferencesTime', 'Show a clock in the top right corner of the screen.');

wiktAddButton( 'WiktionaryPreferencesTimeUTC', 'Change the clock to display UTC, instead of local time.');

wiktAddButton( 'WiktionaryPreferencesTickClock', 'Change the clock to update every second, instead of every page load.');

wiktAddButton( 'WiktIrc2', 'Show a link to a web-based IRC client in the top right-hand corner.');

wiktAddButton( 'WiktionaryPreferencesSmallRC', 'Make the second half of the heading of Special:RecentChanges smaller');

wiktAddButton( 'WiktSidebarTranslation', 'Translate sidebar interwiki links to English');

wiktAddButton( 'WiktFloatNavToggleLeft','Put the [show] button onto the left of the translation bars.');

wiktAddButton( 'WiktPreviewRightTOCs', 'Put the table of contents onto the right of entries.' );

wiktAddSeparator('Preferences that change the display of entries. [May only work with the Monobook skin]');

wiktAddButton( 'WiktionaryPreferencesHideLinesBetweenLanguages', 'Hide the horizontal separator between each language section.');

wiktAddButton( 'WiktionaryPreferencesHideQualifierParens', 'Hide the parentheses around list item qualifiers.');

wiktAddButton( 'WiktionaryPreferencesItalicParens', 'Italicize the punctuation (parentheses and colon) around italic text.');

wiktAddButton( 'WiktHideAllParens', 'Hide the maximal amount of parentheses. [Can cause sentences to appear ungrammatical]'); wiktAddButton( 'WiktionaryPreferencesHideTransitivity', 'Hide the “transitive” and “intransitive” qualifiers in definitions. [Can cause context tags to look odd]');

wiktAddButton( 'WiktionaryPreferencesHideSister', 'Hide the boxes that link to Wikipedia.');

wiktAddButton( 'WiktionaryPreferencesHideRankings', 'Hide the boxes containing word frequency rankings.');

//there’s a typo somewhere here, but I’m not seeing it… //See MediaWiki:Monobook.js wiktAddButton( 'WiktionaryPreferencesShowNav', 'Show the translation sections expanded, instead of having them collapsed.'); wiktAddButton( 'WiktionaryPreferencesHideTranslations', 'Hide the translation sections entirely. [Instead of having them shown collapsed]');

wiktAddButton( 'WiktionaryPreferencesBoxedInflections', 'Display the inflection of some words in boxes instead of a line of text. [May cause layout glitches]'); wiktAddButton( 'WiktionaryPreferencesIndentSeeAlso', 'Indent the “See also” lines more than usual.');

wiktAddButton( 'WiktFormOfPlain', 'Show “form of” definitions with a plain (only wikilinked) lemma. (Default is with a bold lemma.)'); wiktAddButton( 'WiktFormOfItalicQualifier', 'Show “form of” definitions with an italic definition (“qualifier”) and plain (only wikilinked) lemma. (Default is with a bold lemma.)'); wiktAddButton( 'WiktFormOfItalicLemma', 'Show “form of” definitions with an italic lemma. (Default is with a bold lemma.)'); wiktAddButton( 'WiktFormOfItalicQualifierBoldLemma', 'Show “form of” definitions with an italic definition (“qualifier”) and bold lemma. (Default is with a bold lemma.)'); wiktAddButton( 'WiktLatnMentionBold', 'Show other Latin (Roman) script mentions in bold. (Default is in italics.)'); wiktAddButton( 'WiktMentionGlossSingleQuotes', 'Show English glosses for mentioned terms in single quotes. (Default is in double quotes.)'); wiktAddButton( 'WiktHideTrGlossParens', 'Hide parentheses around transliterations and glosses.'); wiktAddButton( 'WiktHideGlossParens', 'Hide parentheses around glosses.'); wiktAddButton( 'WiktPlainTransliterations', 'Show parenthesized plain (non-italic) transliterations.'); wiktAddSeparator('Preferences relating to navigation and editing.');

wiktAddButton( 'WiktionaryDisableAutoRedirect', 'Disable the javascript redirect between pages that differ only in case.');

// User:Lupin/popups.js wiktAddButton( 'WiktionaryPreferencesPopUps', 'Use w:User:Lupin/popups.js to provide page previews and useful buttons when hovering on a normal link.');

wiktAddButton( 'WiktPrefConnelReformat', 'Use User:Connel_MacKenzie/reformat.js to reformat pages semi-automatically. [Do NOT use this unless you know Wiktionary policy better than the back of your hand.]');

wiktAddButton( 'WiktQuickLookup', 'Automatically look up words that are double-clicked on in Wiktionary.');

wiktAddButton( 'WiktAddProminentInterwikis', 'Show an interwiki link under the language heading when one exists in the sidebar.' );

wiktAddButton( 'WiktAccelerateFormCreation', 'Add accelarated creation links for common inflections of some words.');

wiktAddButton( 'WiktAssistedEditing', 'Add input boxes to pages to assist with adding translations.');

wiktAddButton( 'WiktAjaxTransLinks', 'Color translation links orange instead of blue if the target language is missing on an existing page.');

wiktAddButton( 'WiktMakeRedLinksBlack', 'Make red-links on some inflection tables look black.');

wiktAddSeparator('Experiments – these are likely to be buggy and may not work in very common browsers.');

wiktAddButton( 'WiktAddStructure', 'Use User:Conrad.Irwin/parser.js to provide two different views of most pages.'); wiktAddButton( 'WiktFilterContributions', 'Filter out your own contributions from Special:Contributions'); wiktAddButton( 'WiktNearbyPages', 'Add links to previous and next pages'); // experimental spell checkers are both down atm // wiktAddButton( 'WiktionaryPreferencesSpellCheck', 'Add a “Check Spelling” button to edit pages — Experimental — only works for 10KB or less – The spellcheck in Firefox 1.5 is much better'); //wiktAddButton( 'WiktAspellPrototype','(Experimental) Use the aspell checker on User:Amgine’s http://devtionary.info to check search results. (WARNING this site is independent of the WMF and this utility may go offline without warning. Your IP address may be recorded in the server logs there, but no information about your Wiktionary account is sent.)') // If they have a delete button on this page, they are a sysop. var isSysop = document.getElementById('ca-delete'); if ( !isSysop ) return; wiktAddSeparator( 'Sysop-only functions: '); wiktAddButton( 'WiktPrefDelCmnt', 'Replace text in deletion log comment'); wiktAddButton( 'WiktPrefPatrol', 'Patrolling enhancements – add a (mark) next to (diff) to mark as patrolled without leaving Special:RC. Use popups above, to hover over (diff) links, then click (mark).'); wiktAddButton( 'WiktPrefPatrolFast', 'Patrol in “expert mode” with no alerts – all whitelisted users’ edits are quietly marked, bottom to top.'); wiktAddButton( 'WiktPrefPatrolRefresh', 'Refresh Special:RecentChanges every 5 minutes'); //wiktAddButton( 'WiktPrefVOA', 'Use the Uber-Popups from VOA – WARNING – DANGEROUS'); wiktAddButton( 'WiktCIDRRangeContribs', 'Adds a CIDR Range Contributions check to Special:User contributions'); wiktAddButton( 'WiktBlockedNotice','Add a box to the top of user-related pages if the user is blocked from editing.'); }

addOnloadHook( CustomizePreferencesPage );