User:Restu20/articlePreview.js

From Wikidata
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.
var title = $('.wb-sitelinks-link-en a').text();
if (title !== '') {
  $.getJSON('//en.wikipedia.org/w/api.php?action=query&prop=extracts&exintro&exchars=2000&titles='+title+'&format=json&callback=?', function(data) {
    $('#x-articlepreview').append('<h4>Inglese</h4>' + data.query.pages[Object.keys(data.query.pages)[0]].extract);
  });
}
title = $('.wb-sitelinks-link-it a').text();
if (title !== '') {
  $.getJSON('//it.wikipedia.org/w/api.php?action=query&prop=extracts&exintro&exchars=1000&titles='+title+'&format=json&callback=?', function(data) {
    $('#x-articlepreview').append('<h4>Italiano</h4>' + data.query.pages[Object.keys(data.query.pages)[0]].extract);
  });
}
title = $('.wb-sitelinks-link-fr a').text();
if (title !== '') {
  $.getJSON('//fr.wikipedia.org/w/api.php?action=query&prop=extracts&exintro&exchars=1000&titles='+title+'&format=json&callback=?', function(data) {
    $('#x-articlepreview').append('<h4>Francese</h4>' + data.query.pages[Object.keys(data.query.pages)[0]].extract);
  });
}
title = $('.wb-sitelinks-link-de a').text();
if (title !== '') {
  $.getJSON('//de.wikipedia.org/w/api.php?action=query&prop=extracts&exintro&exchars=1000&titles='+title+'&format=json&callback=?', function(data) {
    $('#x-articlepreview').append('<h4>Tedesco</h4>' + data.query.pages[Object.keys(data.query.pages)[0]].extract);
  });
}
$('.wb-widget-container').html('<div id="x-articlepreview" style="max-width:35em;margin-left:30px;"><h3>Article preview</h3></div>');