Adds button to Pins for navigating directly to source
目前為
// ==UserScript==
// @name Pinterest++
// @description Adds button to Pins for navigating directly to source
// @author ifugu
// @version 1.0.14
// @include http://*pinterest.com/*
// @include https://*pinterest.com/*
// @grant GM_xmlhttpRequest
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
//@history 1.0.14 fixed selector for base pin element
// @history 1.0.12 fixed problem in FF where we can't write to document before changing its location
// @history 1.0.11 fixing window opening inside onload callback (was opening in new window instead of a tab)
// @history 1.0.2 fetching source link after button is clicked instead of on hover
// @history 0.9.0 initial release
// @namespace https://greasyfork.org/users/2306
// ==/UserScript==
(function () {
hookUpPinHoverEvent();
})();
function hookUpPinHoverEvent() {
$(document.body).on('mouseover', '.Pin' ,function(){
var $pin = $(this),
$buttonWrapper = $pin.find('.repinSendButtonWrapper');
if (!$buttonWrapper.find('.sourceLaunchButton').length) {
var $pinLink = $pin.find('.pinImageWrapper'); //richPinMetaLink
if ($pinLink.length) {
var href = window.location.origin + $pinLink.attr('href'),
$btn = $('<button type="button" class="rounded Button likeSmall btn hasText sourceLaunchButton" style="margin-top: 3px; float: left; clear: left"><span class="buttonText">Visit Source</span></button>');
$buttonWrapper.append($btn);
$btn.click(function () {
var $btn = $(this),
dataHref = $btn.attr('data-href');
if (dataHref && dataHref.length)
window.open(dataHref);
else {
$btn.attr('disabled', 'disabled').html('retrieving link ...');
var w = window.open();
if ($.browser.webkit)
w.document.write('<b><i>Navigating to source page ...</i></b>');
GM_xmlhttpRequest({
method: 'GET',
url: href,
onload: function(response) {
var $sourceLink = $('.richPinNameLink, .paddedPinLink', response.responseText);
if ($sourceLink.length) {
var sourceHref = $sourceLink.first().attr('href');
if (sourceHref && sourceHref.length) {
$btn.html('opening ...').attr('data-href', sourceHref);
w.location = sourceHref;
$btn.removeAttr('disabled').html('Visit Source');
}
else
$btn.html('Unable to retrieve source link');
}
}
});
}
});
}
}
});
}