Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to change what to get when a page loads #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions JWB.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ JWB.api.submit = function(page) {
JWB.status('done', true);
JWB.next();
};
JWB.api.preview = function() {
JWB.api.preview = function(callback) {
if (JWB.isStopped) return; // prevent new API calls when stopped
JWB.status('preview');
JWB.api.call({
Expand All @@ -538,6 +538,10 @@ JWB.api.preview = function() {
mw.loader.using(response.parse.modules.concat(response.parse.modulescripts, response.parse.modulestyles), function() {
mw.hook('wikipage.content').fire($('#resultWindow .mw-parser-output'));
JWB.status('done', true);

if (typeof(callback) === 'function') {
callback();
}
});
});
};
Expand Down Expand Up @@ -1338,14 +1342,21 @@ JWB.editPage = function(newContent) {
$('#articleList').val($.trim($('#articleList').val()) + '\n' + JWB.list[0]); //move current page to the bottom
JWB.next();
return;
} else if (JWB.bot && $('#autosave').prop('checked')) {
JWB.api.diff(function() {
}

var onLoadFunctions = {
diff: JWB.api.diff,
preview: JWB.api.preview
};
var autoSaveCallback = JWB.bot && $('#autosave').prop('checked')
? function() {
//timeout will take #throttle's value * 1000, if it's a number above 0. Currently defaults to 0.
setTimeout(JWB.api.submit, Math.max(+$('#throttle').val() || 0, 0) * 1000, JWB.page.name);
});
} else {
JWB.api.diff();
}
}
: null;

var onLoadFunction = onLoadFunctions[$('#onLoad').val()] || onLoadFunctions.diff;
onLoadFunction(autoSaveCallback);
};

//Adds a line to the logs tab.
Expand Down Expand Up @@ -1901,6 +1912,11 @@ JWB.init = function() {
'<button class="editbutton" id="diffButton" disabled accesskey="d">'+JWB.msg('editbutton-diff')+'</button>'+
'<button id="replacesButton">'+JWB.msg('button-open-popup')+'</button>'+
findreplace+
JWB.msg('on-load')+
' <select id="onLoad">'+
'<option value="diff" selected>'+JWB.msg('on-load-diff')+'</option>'+
'<option value="preview">'+JWB.msg('on-load-preview')+'</option>'+
'</select>'+
'<hr>'+
'<label><input type="checkbox" id="enableRETF"> '+
JWB.msg('label-enable-RETF',
Expand Down
3 changes: 3 additions & 0 deletions i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ JWB.messages.en = {
'In this JWB script, the _ flag treats underscores and spaces as the same entity. Use with caution.',
'label-ignore-comment': 'Ignore unparsed content',
'tip-ignore-comment': 'Ignore comments and text within nowiki, source, math, or pre tags.',
'on-load': 'On load:',
'on-load-diff': 'Show diff',
'on-load-preview': 'Show preview',
'label-enable-RETF': 'Enable $1',
'label-RETF': 'RegEx Typo Fixing',
'tip-refresh-RETF': 'Refresh the typos list for new modifications.',
Expand Down