cutt.ly 精简页面结果

使用[Cutt URL]按钮进行缩址时,页面上只保留目前的缩址 (本脚本须搭配 cutt.ly 缩址按钮一起服用 https://greasyfork.org/scripts/401540-cutt-ly-url-shorten-button)

当前为 2020-04-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name cutt.ly compact layout
  3. // @name:zh-TW cutt.ly 精簡頁面結果
  4. // @name:zh-CN cutt.ly 精简页面结果
  5. // @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)
  6. // @description:zh-TW 使用[Cutt URL]按钮進行縮址時,頁面上只保留目前的縮址 (本腳本須搭配 cutt.ly 縮址按鈕一起服用 https://greasyfork.org/scripts/401540-cutt-ly-url-shorten-button)
  7. // @description:zh-CN 使用[Cutt URL]按钮进行缩址时,页面上只保留目前的缩址 (本脚本须搭配 cutt.ly 缩址按钮一起服用 https://greasyfork.org/scripts/401540-cutt-ly-url-shorten-button)
  8. // @namespace https://greasyfork.org/zh-TW/users/393133-evan-tseng
  9. // @version 0.1
  10. // @author Evan Tseng
  11. // @run-at document-end
  12. // @match *://cutt.ly/*
  13. // @grant none
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18. const urlParams = new URLSearchParams(window.location.search),
  19. shortenit = urlParams.get('shortenit'),
  20. windowWidth = 250,
  21. windowHeight = 77;
  22.  
  23. // 精簡頁面
  24. const compactPage = function(){
  25. var shortURL = document.querySelector("#results #sortable li:first-child #link").innerText;
  26. document.body.innerHTML='<div style="padding:2mm; margin:0 auto; text-align:center; background:#555">'+
  27. '<input id="url" type="test" value="' + shortURL + '" style="width:100%; text-align:center; border-radius:5px"/><br/>'+
  28. '<button id="copy_btn" style="padding:0 1em; margin: 2mm 0 0">copy URL &amp; close</button></div>';
  29. shortURL = document.querySelector("#url");
  30. shortURL.select();
  31. document.querySelector("#copy_btn").addEventListener("click", function(){
  32. shortURL.select();
  33. document.execCommand('copy');
  34. window.close();
  35. });
  36. };
  37.  
  38. // 顯示正在縮址的提示
  39. const displayOverlay = function(){
  40. window.resizeTo(windowWidth, windowHeight);
  41. window.moveTo((screen.width-windowWidth)/2, (screen.height-windowHeight)/5);
  42. document.body.style.backgroundColor = "#555";
  43. document.body.style.overflow = "hidden";
  44. var overlay = document.createElement("div");
  45. document.body.appendChild(overlay);
  46. 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");
  47. overlay.innerText = "Shortening...";
  48. };
  49.  
  50. // 監視頁面變動來觸發精簡頁面程序
  51. const mo = function(){
  52. var target = document.body,
  53. config = { childList: true },
  54. i=0,
  55. observer = new MutationObserver(function(mutations) {
  56. if(++i > 1) {
  57. observer.disconnect();
  58. compactPage();
  59. }
  60. });
  61. observer.observe(target, config);
  62. };
  63.  
  64. if(shortenit.length) {
  65. displayOverlay();
  66. mo();
  67. }
  68. })();