User:ITechieGamer/test.js

$(document).ready(function { var $testGroup = $(' ').append($('Test scripts ')),      $testBody = $(' '),      $testLink = $('Add update video');  $($testGroup.append($testBody.html($('').append($('').html($testLink))))).insertBefore('#p-socialProfiles');  $('#t-test1').click(testFunction); });

function testFunction {

var editToken = mw.user.tokens.get('editToken'), output, pageName = mw.config.get('wgPageName'), ytVidId = prompt('YouTube video ID'), isSuccess = 0;

console.log('Working on the raw contents of this page');

$.ajax({ type: 'GET',  url: mw.util.wikiScript('index'),  data: {    title: pageName,    action: 'raw'  },  async: false,  success: function(response) {    output = response;  },  error: function(xhr, textStatus, error) {    console.log(xhr.statusText + '\n' + textStatus + '\n' + error);    alert('Error while getting raw contents of "' + pageName + '"');    return;  } });

if(output.includes("== Trivia ==")) output = output.replace('== Trivia ==', '== Video ==\nVideo made by slicedlime:\n\n\n== Trivia =='); else if(output.includes("== References ==")) output = output.replace('== References ==', '== Video ==\nVideo made by slicedlime:\n\n\n== References =='); else { console.log('§ Trivia or § References could not be found'); alert('§ Trivia or § References could not be found'); return; }

console.log('Processing data');

$.ajax({ type: 'POST',  url: mw.util.wikiScript('api'),  data: {    format: 'json',    formatversion: 2,    action: 'edit',    title: pageName + '/Update Video',    text: ' Category\x3aUpdate videos ',    summary: 'Added update video',    bot: true,    minor: true,    createonly: true,    token: editToken  },  dataType: 'json',  async: false,  success: function {    isSuccess++;  },  error: function(xhr, textStatus, error) {    console.log(xhr.statusText + '\n' + textStatus + '\n' + error);    alert('Error while editing pages');    return;  } });

$.ajax({ type: 'POST',  url: mw.util.wikiScript('api'),  data: {    format: 'json',    formatversion: 2,    action: 'edit',    title: pageName,    text: output,    summary: 'Added update video',    bot: true,    minor: true,    token: editToken  },  dataType: 'json',  async: false,  success: function {    isSuccess++;  },  error: function(xhr, textStatus, error) {    console.log(xhr.statusText + '\n' + textStatus + '\n' + error);    alert('Error while editing pages');    return;  } });

console.log('Success: ' + isSuccess + ' of 2'); alert('Success: ' + isSuccess + ' of 2');

}