User:Acagastya/leftMenu.js

From Wikinews, the free news source you can write!
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences. — More skins

/*
 # Tasks
 1. Select navigation section
  a. Remove useless contents in <ul>
  c. Add link to S:AF
  b. Add link to CAT:Rev
  d. Update the navigation section
 1. Update contents of navigation section
  a. Create CAT:REV
  b. Create S:AF
  c. Arrange contents in navigation section
 2. Delete Wikinews section
 3. Delete Region section
 4. Delete Print/export section
 5. Rearrange the sections Logo > Nav > Tools > Languages
 6. remove VE
*/

setTimeout(function changeLeftMenu() {
  // Create link for CAT:REV
  const reviewLink = document.createElement('a');
  reviewLink.setAttribute('href', '/wiki/Category:Review');
  reviewLink.setAttribute('title', 'Visit articles to be reviewed');
  reviewLink.innerText = 'Articles to be reviewed';
  // Create li for CAT:REV
  const reviewListItem = document.createElement('li');
  reviewListItem.appendChild(reviewLink);
  reviewListItem.setAttribute('id', 'n-cat-rev');

  // Create link for Special:AbuseFilter
  const AFLink = document.createElement('a');
  AFLink.setAttribute('href', '/wiki/Special:AbuseFilter');
  AFLink.setAttribute('title', 'See AbuseFilter');
  AFLink.innerText = 'Abuse Filter';
  // Create li for S:AF
  const AFListItem = document.createElement('li');
  AFListItem.appendChild(AFLink);
  AFListItem.setAttribute('id', 'n-s-af');

  // Order of IDs for NavBox
  const navBoxIDs = [
    'n-recentchanges',
    reviewListItem,
    'n-mainpage-description',
    'n-randompage',
    AFListItem
  ];
  const navBoxNodes = navBoxIDs.map(id =>
    typeof id == 'string' ? document.getElementById(id) : id
  );

  const linkBox = document.getElementById('p-navigation');
  const divBody = [...linkBox.children][1];
  divBody.innerHTML = null;

  const ul = document.createElement('ul');
  navBoxNodes.forEach(node => ul.appendChild(node));

  divBody.appendChild(ul);

  // delete sections: Wikinews, Regions, Print/export
  const wikinewsBox = document.getElementById('p-Wikinews');
  wikinewsBox.remove();
  const regionBox = document.getElementById('p-Regions');
  regionBox.remove();
  const printBox = document.getElementById('p-coll-print_export');
  printBox && printBox.remove();

  const articleToolsHeading = document.createElement('h3');
  articleToolsHeading.innerText = 'Article Tools';
  articleToolsHeading.setAttribute('id', 'p-article-tools-label');

  const articleToolsList = document.createElement('ul');
  articleToolsList.setAttribute("class", "no-bullet");

  const articleToolsBody = document.createElement('div');
  articleToolsBody.setAttribute('class', 'body');

  articleToolsBody.appendChild(articleToolsList);

  const articleTools = document.createElement('div');
  articleTools.setAttribute('id', 'p-article-tools');
  articleTools.setAttribute('class', 'portal');
  articleTools.setAttribute('role', 'navigation');
  articleTools.setAttribute('aria-labelledby', 'p-article-tools-label');

  articleTools.appendChild(articleToolsHeading);
  articleTools.appendChild(articleToolsBody);

  const panel = document.getElementById('mw-panel');
  const panelChildrenIDs = [
    'p-logo',
    'p-navigation',
    articleTools,
    'p-tb',
    'p-lang',
    'p-wikibase-otherprojects'
  ];
  const panelChildren = panelChildrenIDs.map(id =>
    typeof id == 'string' ? document.getElementById(id) : id
  );
  panel.innerHTML = null;
  panelChildren.forEach(child => child && panel.appendChild(child));
  // document.getElementById('p-logo').remove();
  if(mw.config.get('wgNamespaceNumber') != 0)  document.getElementById('p-article-tools').remove();

  // remove visual editor
  const visEditor = document.getElementById('ca-ve-edit');
  if(visEditor) visEditor.remove()
}, 0);