// ==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 // @downloadURL 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='
'+ '
'+ '
'; 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(); } })();