User:RoyZuo/SearchFreeMedia.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
// 1 click jump to search Flickr or YouTube for free files
// search keyword is "pagename" minus substring starting with " by " 
var titlekey = mw.config.get('wgTitle').replace(/\sby\s.+/g, "");
jQuery(document).ready(function(){
    'use strict';
    //license numbers https://commons.wikimedia.org/wiki/Commons_talk:Flickr_files/Archive_2#Flickr_license_attribute_numbers
    mw.util.addPortletLink('p-tb',
    "https://www.flickr.com/search/?license=4%2C5%2C7%2C8%2C9%2C10&view_all=1&sort=date-taken-desc&text=" +
    encodeURIComponent(titlekey), 
    'Search Flickr free', 
    'ca-SearchFreeMedia', 
    "Find Commercial use & mods allowed on Flickr");
    mw.util.addPortletLink('p-tb',
    "https://www.youtube.com/results?sp=CAISAjAB&search_query=" +
    encodeURIComponent(titlekey), 
    'Search YouTube CC-BY',
    'ca-SearchFreeMedia', 
    "Find CC-BY on YouTube");
});