cutt.ly 縮短網址按鈕

在頁面左下角設置一個縮短網址的按鈕,這會開個新視窗來檢視 cutt.ly 的縮址結果

目前為 2020-05-05 提交的版本,檢視 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name		cutt.ly URL shorten button
// @name:zh-TW		cutt.ly 縮短網址按鈕
// @name:zh-CN		cutt.ly 缩短网址按钮
// @description		Add a URL shorten button to the bottom left corner. It will create a new window for the shortened URL of cutt.ly
// @description:zh-TW	在頁面左下角設置一個縮短網址的按鈕,這會開個新視窗來檢視 cutt.ly 的縮址結果
// @description:zh-CN	在页面左下角设置一个缩短网址的按钮,这会开个新视窗来查看 cutt.ly 的缩址结果
// @namespace	https://greasyfork.org/zh-TW/users/393133-evan-tseng
// @version		0.15
// @author		Evan Tseng
// @run-at		document-end
// @include		*://*
// @exclude		http://cutt.ly/*
// @exclude		https://cutt.ly/*
// @grant		none
// ==/UserScript==

(function() {
	'use strict';
	if(self==top) {
		var addCuttButton = (function() {
			if(document.readyState !== "loading") {
				const newWindow = window.open,
					  CuttURL = 'https://cutt.ly/?shortenit=' + encodeURIComponent(document.URL);
				let strWindowFeatures = 'width=500,height=874,top='+((screen.height-874)/4)+',left='+((screen.width-500)/2)+',menubar=no,toolbar=no,location=no,status=no',
					cssStyle = document.createElement('style'),
					css = `.__shorten_wrap__ { position: fixed; bottom:33mm; left:-25pt; z-index:2147483647 }
.__shorten_btn__ { position:absolute; font: 400 11pt Helvetica; width:60pt; color:#334; text-shadow:1px -1px rgba(255,255,255,.6); background:linear-gradient(5deg, rgba(170,170,175,.85) 0, rgba(210,210,215,.8) 50%, rgba(170,170,175,.85) 100%); padding:.3em 0 1em; margin:0; line-height:1; border:1px solid rgba(0,0,0,.4); border-radius:5pt; cursor:pointer; transform:rotate(90deg); transition:.15s }
.__shorten_btn__:hover { background:linear-gradient(5deg, rgba(190,190,190,.95) 0, rgba(230,230,230,.95) 50%, rgba(190,190,190,.95) 100%); border:1px solid rgba(0,0,0,.4); box-shadow:1px 0 4pt rgba(0,0,0,.5) }
.__shorten_btn__:active { color:#cdf; text-shadow:-1px 1px #000; background:rgba(125,125,133,.8); border-color:rgba(255,255,255,.6); box-shadow:inset 1px 0 4pt rgba(0,0,0,.7); transition:0s }
.__shorten_wrap__ .__notify__ { position:absolute; left:17mm; top:-.7em; padding:2mm; color:#444; background:#ecece4; white-space:nowrap; overflow:hidden; border-radius:2mm; box-shadow: 0 0 1mm 1px rgba(0,0,0,.3); visibility:hidden; opacity:0; transition:.3s }
.__shorten_wrap__:hover .__notify__ { visibility:visible; opacity:1; transition:.3s }
.__shorten_wrap__ a { color:#448; }
@media print { .__shorten_wrap__ {display:none;} }`;
				if(cssStyle.styleSheet)	cssStyle.styleSheet.cssText = css;
				else	cssStyle.appendChild(document.createTextNode(css));
				document.querySelector('head').appendChild(cssStyle);

				let shortenWrap = document.createElement('div');
				shortenWrap.setAttribute("class", "__shorten_wrap__");
				document.body.appendChild(shortenWrap);

				let shortenButton = document.createElement('button');
				shortenButton.setAttribute("class", "__shorten_btn__");
				shortenButton.innerText = "Cutt URL";
				shortenWrap.appendChild(shortenButton);

				if(window.location.href.indexOf("%")==-1) {
					shortenButton.addEventListener("click", function(){
						newWindow(CuttURL, "Cutt URL", strWindowFeatures);
					});
				}
				else {
					let noti = document.createElement("div");
					noti.setAttribute("class","__notify__");
					noti.innerHTML = "Cutt-URL button does not support the URL which contains <b><span style='color:#744'>%</span></b> character.<br/>Please visit <a href='http://cutt.ly/' target='_blank'>http://cutt.ly/</a> and shorten manually.";
					shortenWrap.appendChild(noti);
				}
			}
			else setTimeout(addCuttButton, 500);
		})();
	}
})();