User:So9q/openalex-search-link-on-lexemes.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)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/*
 * Simple script to add a link to Ordia in the Tools section on items.
 * Forked from https://www.wikidata.org/wiki/User:Fnielsen/scholia-link.js by Fnielsen.
 */

( function ( mw, $ ) {
	var lemma = $(".lemma-widget_lemma-value").text();
	if ( !lemma ) {
		return;
	}
	// Add portlet link for item
	mw.util.addPortletLink(
		'p-tb',
		'//api.openalex.org/works?filter=abstract.search:' + encodeURI(lemma),
		'Search for lemma in OpenAlex abstracts',
		't-oa-abstracts',
		'This Wikidata lexeme in OpenAlex Work abstracts'
	);
	mw.util.addPortletLink(
		'p-tb',
		'//api.openalex.org/works?filter=title.search:' + encodeURI(lemma),
		'Search for lemma in OpenAlex titles',
		't-oa-abstracts',
		'This Wikidata lexeme in OpenAlex Work titles'
	);
}( mediaWiki, jQuery ) );