Jump to content

User:Habst/newspapersCom.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// newspapers
{
  const clipA = document.querySelector('#viewer-information-pane div.col-sm-7 > a');
  const clipTitle = clipA.innerText;
  const paper = document.querySelector('#paperIDLabel > a').innerText;
  const dtpg = document.querySelector('#content > div > div.order-sm-4.text-center.d-none.d-md-block.px-0.col-12.col-sm > p').innerText;
  const pg = dtpg.split(' ').at(-1);
  const md = dtpg.split(', ')[1].split(' ').reverse().join(' ').replace(/0([1-9])/, '$1');
  const yr = dtpg.split(' ')[3];
  const now = new Date();
  const accessDate = `${now.getDate()} ${now.toLocaleString('en-US', { month: 'long' })} ${now.getFullYear()}`;
  const clipUrl = clipA.href.replace('https://www-newspapers-com.wikipedialibrary.idm.oclc.org/', 'https://www.newspapers.com/');
  const out = `<ref>{{cite web |title=${clipTitle} |url=${clipUrl} |publisher=${paper} |access-date=${accessDate} |page=${pg} |date=${md} ${yr}}}</ref>`;
  out;
}