User:Lectrician1/Discuss.js
Jump to navigation
Jump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
jQuery(function () {
var urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('diff')) {
var preloadPage = 'User:Lectrician1/new_revision_discussion';
var talkPagePath = $('#ca-talk > a').attr('href');
var revisionUsername = $('#mw-diff-ntitle2 > a > bdi').html();
var possibleRevisionDescription = $('#mw-diff-ntitle3 > span').text();
// if possibleRevisionDescription starts with '(' then slice the ends. otherwise return ''
var revisionDescription = possibleRevisionDescription.startsWith('(') ? possibleRevisionDescription.slice(1, -1) + ' ' : '';
var preloadParams = [
location.host,
urlParams.get('diff'),
urlParams.get('oldid'),
urlParams.get('title'),
revisionUsername
];
var preloadTitle = "Revision ".concat(revisionDescription, "by ").concat(revisionUsername);
var preloadParamsText = preloadParams.map(function (param) { return "&preloadparams[]=".concat(param); }).join('');
var newTopicURL = encodeURI("".concat(location.origin).concat(talkPagePath, "?action=edit§ion=new&preloadtitle=").concat(preloadTitle, "&preload=").concat(preloadPage).concat(preloadParamsText));
$('#mw-diff-ntitle1 > strong').append("\n\t\t\t<span>(<a href=\"".concat(newTopicURL, "\">discuss</a>)</span>\n\t\t"));
}
});