Pinterest++

Adds button to Pins for navigating directly to source

目前為 2015-03-16 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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');
								}
							}
						});
					}
				});

			}
		}
	});
}