cutt.ly compact layout

When shortening with [Cutt URL] button, delete every thing in the result page except the shortened URL. (this script must be used with the cutt.ly shorten button. https://greasyfork.org/scripts/401540-cutt-ly-url-shorten-button)

Per 22-04-2020. Zie de nieuwste versie.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

// ==UserScript==
// @name		cutt.ly compact layout
// @name:zh-TW	cutt.ly 精簡頁面結果
// @name:zh-CN	cutt.ly 精简页面结果
// @description			When shortening with [Cutt URL] button, delete every thing in the result page except the shortened URL. (this script must be used with the cutt.ly shorten button. https://greasyfork.org/scripts/401540-cutt-ly-url-shorten-button)
// @description:zh-TW	使用[Cutt URL]按钮進行縮址時,頁面上只保留目前的縮址 (本腳本須搭配 cutt.ly 縮址按鈕一起服用 https://greasyfork.org/scripts/401540-cutt-ly-url-shorten-button)
// @description:zh-CN	使用[Cutt URL]按钮进行缩址时,页面上只保留目前的缩址 (本脚本须搭配 cutt.ly 缩址按钮一起服用 https://greasyfork.org/scripts/401540-cutt-ly-url-shorten-button)
// @namespace	https://greasyfork.org/zh-TW/users/393133-evan-tseng
// @version		0.1
// @author		Evan Tseng
// @run-at		document-end
// @match		*://cutt.ly/*
// @grant		none
// ==/UserScript==

(function() {
	'use strict';
	const urlParams = new URLSearchParams(window.location.search),
		  shortenit = urlParams.get('shortenit'),
		  windowWidth = 250,
		  windowHeight = 77;

	// 精簡頁面
	const compactPage = function(){
		var shortURL = document.querySelector("#results #sortable li:first-child #link").innerText;
		document.body.innerHTML='<div style="padding:2mm; margin:0 auto; text-align:center; background:#555">'+
			'<input id="url" type="test" value="' + shortURL + '" style="width:100%; text-align:center; border-radius:5px"/><br/>'+
			'<button id="copy_btn" style="padding:0 1em; margin: 2mm 0 0">copy URL &amp; close</button></div>';
		shortURL = document.querySelector("#url");
		shortURL.select();
		document.querySelector("#copy_btn").addEventListener("click", function(){
			shortURL.select();
			document.execCommand('copy');
			window.close();
		});
	};

	// 顯示正在縮址的提示
	const displayOverlay = function(){
		window.resizeTo(windowWidth, windowHeight);
		window.moveTo((screen.width-windowWidth)/2, (screen.height-windowHeight)/5);
		document.body.style.backgroundColor = "#555";
		document.body.style.overflow = "hidden";
		var overlay = document.createElement("div");
		document.body.appendChild(overlay);
		overlay.setAttribute("style", "position:fixed; left:0; top:0; width:100vw; height:100vh; color:#ddd; background:#555; text-align:center; line-height:100vh; z-index:5");
		overlay.innerText = "Shortening...";
	};

	// 監視頁面變動來觸發精簡頁面程序
	const mo = function(){
		var target = document.body,
			config = { childList: true },
			i=0,
			observer = new MutationObserver(function(mutations) {
				if(++i > 1) {
					observer.disconnect();
					compactPage();
				}
			});
		observer.observe(target, config);
	};

	if(shortenit.length) {
		displayOverlay();
		mo();
	}
})();