User:Ahecht/Scripts/draft-sorter.js: Difference between revisions

Content deleted Content added
outlink-topic-model
Sync with sandbox
Line 6:
( function ( $, mw ) { mw.loader.using( ["mediawiki.api", "jquery.chosen", "oojs-ui-core"], function () {
mw.loader.load( "mediawiki.ui.input", "text/css" );
var api = new mw.Api();
 
if ( mw.config.get( "wgNamespaceNumber" ) !== 118 ) {
Line 74 ⟶ 75:
var wikiprojects = {};
 
new mw.Api()api.get( {
action: "query",
titles: "Draft talk:" + mw.config.get( "wgTitle" ),
Line 117 ⟶ 118:
try {
listData = await new mw.Api()api.get( query );
} catch (jsonerror) {
console.warn("Unable to fetch contents of " + listName + ":");
Line 146 ⟶ 147:
$( "#draft-sorter-status" ).append( "<li>Suggested categories from <a href=\"https://www.mediawiki.org/wiki/ORES#Topic_routing\">ORES</a>:<ul id=\"draft-sorter-suggest\"></ul></li>" );
predicts.forEach( function(item) {
function addWithLink(p) {
var addLink = $( "<a>" )
$( "#draft-sorter-suggest" ).append( $( "<li>" )
.text("add")
$( "<li>" ).clicktext( functionitem + " ()" {).append(
$( select"<a>" ).valtext("add").click(
addLink.click( function() {
$( select ).val().concat( [ "WikiProject " + item ] )
$( select ).val(
).trigger("chosen:updated");
$( select ).val().concat( [ "WikiProject " + itemp ] )
} );
).trigger("chosen:updated");
); }
)
).textappend( "add)" )
} );
);}
} );
var singularItem = item.replace(/s$/, '');
if( !existingProjects.includes( "WikiProject " + item )
&& wikiprojects[item]
) { //Prediction matches a WikiProject and doesn't already exist
addWithLink(item);
$( "#draft-sorter-suggest" ).append( $( "<li>" )
.append( item + " (" )
.append( addLink )
.append( ")" )
);
} else if( singularItem != item
&& !existingProjects.includes( "WikiProject " + singularItem )
&& wikiprojects[singularItem]
) { //Singular form of prediction matches a WikiProject and doesn't exist
.appendaddWithLink( singularItem + " (" );
addLink.click( function() {
$( select ).val(
$( select ).val().concat( [ "WikiProject " + singularItem ] )
).trigger("chosen:updated");
} );
$( "#draft-sorter-suggest" ).append( $( "<li>" )
.append( singularItem + " (" )
.append( addLink )
.append( ")" )
);
} else { //Prediction doesn't match a WikiProject or already exists
$( "#draft-sorter-suggest" ).append(
Line 359 ⟶ 354:
params[prefix + "text"] = text;
 
new mw.Api()api.postWithEditToken( params ).done( function ( data ) {
if ( data && data.edit && data.edit.result && data.edit.result === "Success" ) {
showStatus( "Edit saved successfully! (" )
Line 382 ⟶ 377:
}
 
new mw.Api()api.get( {
action: "query",
titles: "Draft talk:" + mw.config.get( 'wgTitle' ),