diff --git a/gadgets/.eslintrc.json b/- gadgets/.eslintrc.json similarity index 100% rename from gadgets/.eslintrc.json rename to - gadgets/.eslintrc.json diff --git a/gadgets/Gadget-autonum.js b/- gadgets/Gadget-autonum.js similarity index 100% rename from gadgets/Gadget-autonum.js rename to - gadgets/Gadget-autonum.js diff --git a/gadgets/Gadget-markblocked.js b/- gadgets/Gadget-markblocked.js similarity index 100% rename from gadgets/Gadget-markblocked.js rename to - gadgets/Gadget-markblocked.js diff --git a/gadgets/Gadget-popups.js b/- gadgets/Gadget-popups.js similarity index 100% rename from gadgets/Gadget-popups.js rename to - gadgets/Gadget-popups.js diff --git a/gadgets/Gadget-script-installer-core.js b/- gadgets/Gadget-script-installer-core.js similarity index 100% rename from gadgets/Gadget-script-installer-core.js rename to - gadgets/Gadget-script-installer-core.js diff --git a/DraftCleaner/main.js b/DraftCleaner/main.js index d8022d4..6c19ff1 100644 --- a/DraftCleaner/main.js +++ b/DraftCleaner/main.js @@ -44,104 +44,106 @@ Add one of the following to your User:yourName/common.js (at the top) to change This page was assembled from 3 files using my publish.php script. I have an offline test suite with around 100 unit tests for the DraftCleaner and StringFilter classes. */ -async function getWikicode(title) { - let pageIsDeleted = ! mw.config.get('wgCurRevisionId'); - if ( pageIsDeleted ) { - return ''; +( function () { + async function getWikicode( title ) { + const pageIsDeleted = !mw.config.get( 'wgCurRevisionId' ); + if ( pageIsDeleted ) { + return ''; + } + + let wikicode = ''; + title = encodeURIComponent( title ); + await $.ajax( { + url: 'https://en.wikipedia.org/w/api.php?action=parse&page=' + title + '&prop=wikitext&formatversion=2&format=json', + success: function ( result ) { + wikicode = result.parse.wikitext; + }, + dataType: 'json' + } ); + return wikicode; } - var wikicode = ''; - title = encodeURIComponent(title); - await $.ajax({ - url: 'https://en.wikipedia.org/w/api.php?action=parse&page='+title+'&prop=wikitext&formatversion=2&format=json', - success: function (result) { - wikicode = result['parse']['wikitext']; - }, - dataType: "json", - }); - return wikicode; -} - -function goToShowChangesScreen(titleWithNamespaceAndUnderscores, wikicode, editSummary) { - let titleEncoded = encodeURIComponent(titleWithNamespaceAndUnderscores); - let wgServer = mw.config.get('wgServer'); - let wgScriptPath = mw.config.get('wgScriptPath'); - let baseURL = wgServer + wgScriptPath + '/'; - // https://stackoverflow.com/a/12464290/3480193 - $(`
`) - .append($('').val(wikicode)) - .append($('').val(editSummary)) - .append($('').val('preview')) - .append($('').val('Show changes')) - .append($('').val('1')) - .appendTo($(document.body)) //it has to be added somewhere into the - .trigger('submit'); -} - -/** returns the pagename, including the namespace name, but with spaces replaced by underscores */ -function getArticleName() { - return mw.config.get('wgPageName'); -} - -// don't run when not viewing articles -let action = mw.config.get('wgAction'); -let isNotViewing = action != 'view'; -if ( isNotViewing ) { - return; -} - -// don't run when viewing diffs -let isDiff = mw.config.get('wgDiffNewId'); -if ( isDiff ) { - return; -} - -// Don't run in virtual namespaces -let isVirtualNamespace = mw.config.get('wgNamespaceNumber') < 0; -if ( isVirtualNamespace ) { - return; -} - -let menuID = 'p-navigation'; -// @ts-ignore -if ( window.draftCleanerPutInToolsMenu ) { - menuID = 'p-tb'; -// @ts-ignore -} else if ( window.draftCleanerPutInMoreMenu ) { - menuID = 'p-cactions'; -} - -let titleWithNamespaceAndUnderscores = getArticleName(); -let namespaceNumber = mw.config.get('wgNamespaceNumber'); - -let running = false; - -// Add DraftCleaner to the toolbar -mw.loader.using(['mediawiki.util'], function () { - mw.util.addPortletLink(menuID, '#', 'Run DraftCleaner', 'DraftCleanerLink'); - $('#DraftCleanerLink').on('click', async function() { - // prevent running the script while script is already in progress - if ( running ) { - return; - } - running = true; - - mw.notify('Parsing page content...'); - - // get page wikicode - let titleWithNamespaceAndSpaces = titleWithNamespaceAndUnderscores.replace(/_/g, ' '); - let originalWikicode = await getWikicode(titleWithNamespaceAndUnderscores); - let wikicode = originalWikicode; - - let dc = new DraftCleaner(); - wikicode = dc.cleanDraft(wikicode, namespaceNumber, titleWithNamespaceAndSpaces); - - let needsChanges = wikicode != originalWikicode; - if ( needsChanges ) { - let summary = 'clean up ([[User:Novem Linguae/Scripts/DraftCleaner.js|DraftCleaner]])'; - await goToShowChangesScreen(titleWithNamespaceAndUnderscores, wikicode, summary); - } else { - mw.notify('No changes needed!'); - } - }); -}); \ No newline at end of file + function goToShowChangesScreen( titleWithNamespaceAndUnderscores, wikicode, editSummary ) { + const titleEncoded = encodeURIComponent( titleWithNamespaceAndUnderscores ); + const wgServer = mw.config.get( 'wgServer' ); + const wgScriptPath = mw.config.get( 'wgScriptPath' ); + const baseURL = wgServer + wgScriptPath + '/'; + // https://stackoverflow.com/a/12464290/3480193 + $( `` ) + .append( $( '' ).val( wikicode ) ) + .append( $( '' ).val( editSummary ) ) + .append( $( '' ).val( 'preview' ) ) + .append( $( '' ).val( 'Show changes' ) ) + .append( $( '' ).val( '1' ) ) + .appendTo( $( document.body ) ) // it has to be added somewhere into the + .trigger( 'submit' ); + } + + /** returns the pagename, including the namespace name, but with spaces replaced by underscores */ + function getArticleName() { + return mw.config.get( 'wgPageName' ); + } + + // don't run when not viewing articles + const action = mw.config.get( 'wgAction' ); + const isNotViewing = action != 'view'; + if ( isNotViewing ) { + return; + } + + // don't run when viewing diffs + const isDiff = mw.config.get( 'wgDiffNewId' ); + if ( isDiff ) { + return; + } + + // Don't run in virtual namespaces + const isVirtualNamespace = mw.config.get( 'wgNamespaceNumber' ) < 0; + if ( isVirtualNamespace ) { + return; + } + + let menuID = 'p-navigation'; + // @ts-ignore + if ( window.draftCleanerPutInToolsMenu ) { + menuID = 'p-tb'; + // @ts-ignore + } else if ( window.draftCleanerPutInMoreMenu ) { + menuID = 'p-cactions'; + } + + const titleWithNamespaceAndUnderscores = getArticleName(); + const namespaceNumber = mw.config.get( 'wgNamespaceNumber' ); + + let running = false; + + // Add DraftCleaner to the toolbar + mw.loader.using( [ 'mediawiki.util' ], () => { + mw.util.addPortletLink( menuID, '#', 'Run DraftCleaner', 'DraftCleanerLink' ); + $( '#DraftCleanerLink' ).on( 'click', async () => { + // prevent running the script while script is already in progress + if ( running ) { + return; + } + running = true; + + mw.notify( 'Parsing page content...' ); + + // get page wikicode + const titleWithNamespaceAndSpaces = titleWithNamespaceAndUnderscores.replace( /_/g, ' ' ); + const originalWikicode = await getWikicode( titleWithNamespaceAndUnderscores ); + let wikicode = originalWikicode; + + const dc = new DraftCleaner(); + wikicode = dc.cleanDraft( wikicode, namespaceNumber, titleWithNamespaceAndSpaces ); + + const needsChanges = wikicode != originalWikicode; + if ( needsChanges ) { + const summary = 'clean up ([[User:Novem Linguae/Scripts/DraftCleaner.js|DraftCleaner]])'; + await goToShowChangesScreen( titleWithNamespaceAndUnderscores, wikicode, summary ); + } else { + mw.notify( 'No changes needed!' ); + } + } ); + } ); +}() ); diff --git a/statusChanger.js b/statusChanger.js new file mode 100644 index 0000000..289a7b3 --- /dev/null +++ b/statusChanger.js @@ -0,0 +1,126 @@ +// STATUS CHANGER +// Creator: Misza13 +// Modified by Cyberpower678 to simply use /Statussig as a one word indicator +// Only compatible with Cyberpower678's Userspace setup +// Forked by Enterprisey on 2019 Feb 24 to use a "top menu" instead + +$.when( mw.loader.using( [ 'mediawiki.util', 'mediawiki.api' ] ), $.ready ).done( () => { + // Check if the config is defined + if ( typeof ( statusChangerConfig ) == 'undefined' ) { + statusChangerConfig = {}; + } + if ( typeof ( stressChangerConfig ) == 'undefined' ) { + stressChangerConfig = {}; + } + + statusChangerConfig.statusList = [ 'auto', 'green', 'olive', 'darkorange', 'red', 'brown', 'black', 'grey' ]; + statusChangerConfig.statusText = { auto: 'Automatic', green: 'Huggling', olive: 'Online', darkorange: 'Lurking', red: 'Offline', brown: 'Quick Peek', black: 'Absent', grey: 'Retired' }; + statusChangerConfig.statusPage = 'User:' + mw.config.get( 'wgUserName' ) + '/Statussig/sub'; + + stressChangerConfig.statusList = [ 'nul', '-1', '0', '0.01', '1', 'NoPants', 'numb', '2', '3', '4', '4a', '5', '6', '6.5', '7', '8', '9', '10', '11', '∞' ]; + stressChangerConfig.statusText = { nul: 'No status', '-1': 'Polluted', 0: 'Went insane', 0.01: 'Having a life', 1: 'Just fine', NoPants: 'No pants on', numb: 'Numb', 2: 'Tense', 3: 'Stressed', 4: 'Need vacation', '4a': 'On break', 5: 'Run', 6: 'Hospitalized', 6.5: 'Bye Bye', 7: 'Recovering', 8: 'Able to edit', 9: 'Meter fixed', 10: 'Broke again', 11: 'Dead', '∞': 'Nearly die' }; + stressChangerConfig.statusPage = 'User:' + mw.config.get( 'wgUserName' ) + '/StressLevel'; + + const STATUSES = { + auto: 'switching his status to automatically change', + green: 'Huggling', + olive: 'Online', + darkorange: 'Partially Online', + red: 'Offline', + brown: 'Online during absence', + black: 'taking extended absence', + grey: 'retiring or quiting from Wikipedia' + }; + const STRESSES = { + nul: 'shut off his meter', + '-1': 'polluted his meter or is about to go insane', + 0: 'went insane', + 0.01: 'is having a life and you can\'t be part of it :P', + 1: 'is feeling fine', + NoPants: 'is not wearing any pants', + numb: 'is feeling numb', + 2: 'is feeling a bit tense', + 3: 'is pretty stressed right now. Please don\'t push it', + 4: 'is about to blow a gasket. He believes he needs a Wikibreak before he quits Wikipedia', + '4a': 'is on a Wikibreak', + 5: 'is about to explode and may destroy half of Wikipedia', + 6: 'has landed in the hospital', + 6.5: 'is about to be injured in some way', + 7: 'is recovering', + 8: 'is able to start editing again', + 9: 'managed to fix his meter and will be back to full time editing soon', + 10: 'broke his meter again', + 11: 'died. This is NOT a joke.', + '∞': 'is close to dying or just witnessed a nuclear explosion' + }; + + mw.util.addPortlet( 'p-status', 'Status', '#p-cactions' ); + mw.util.addPortlet( 'p-stress', 'Stress', '#p-cactions' ); + + // Add the links + for ( var i = 0; i < statusChangerConfig.statusList.length; i++ ) { + var stat = statusChangerConfig.statusList[ i ]; + mw.util.addPortletLink( + 'p-status', // target tab - new "status" menu + '#', + statusChangerConfig.statusText[ stat ], // link text + 'pt-status-' + stat // id of new button + ).addEventListener( 'click', makeStatusListener( stat ) ); + } + for ( var i = 0; i < stressChangerConfig.statusList.length; i++ ) { + var stat = stressChangerConfig.statusList[ i ]; + mw.util.addPortletLink( + 'p-stress', // target tab - new "status" menu + '#', + stressChangerConfig.statusText[ stat ], // link text + 'pt-stress-' + stat // id of new button + ).addEventListener( 'click', makeStressListener( stat ) ); + } + + function makeStatusListener( stat ) { + return function ( evt ) { + if ( evt ) { + evt.preventDefault(); + } + ( new mw.Api() ).postWithToken( 'csrf', { + action: 'edit', + title: statusChangerConfig.statusPage, + summary: mw.config.get( 'wgUserName' ) + ' is ' + STATUSES[ stat ] + '.', + text: stat, + minor: 'true' + } ).done( ( d ) => { + if ( d && d.edit && d.edit.result && d.edit.result == 'Success' ) { + window.location.reload( true ); + } else { + console.error( d ); + } + } ).fail( ( code, result ) => { + console.error( code, result ); + } ); + }; + } + function makeStressListener( stat ) { + return function ( evt ) { + if ( evt ) { + evt.preventDefault(); + } + ( new mw.Api() ).postWithToken( 'csrf', { + action: 'edit', + title: stressChangerConfig.statusPage, + summary: mw.config.get( 'wgUserName' ) + ' ' + STRESSES[ stat ] + '.', + text: stat, + minor: 'true' + } ).done( ( d ) => { + if ( d && d.edit && d.edit.result && d.edit.result == 'Success' ) { + window.location.reload( true ); + } else { + console.error( d ); + } + } ).fail( ( code, result ) => { + console.error( code, result ); + } ); + }; + } +} ); + +// [[Category:Wikipedia scripts|statusChanger]]