decodeURI & Paste text - Keyboard shortcut

Calling decodeURI to get a nicer and readable URI (Ctrl + Shift + V)

当前为 2016-03-10 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name decodeURI & Paste text - Keyboard shortcut
  3. // @namespace https://github.com/arieljannai/tampermonkey-scripts
  4. // @version 0.1
  5. // @description Calling decodeURI to get a nicer and readable URI (Ctrl + Shift + V)
  6. // @author Ariel Jannai
  7. // @icon https://pixabay.com/static/uploads/photo/2012/04/16/13/10/document-35941_960_720.png
  8. // @include /^https?://.*/
  9. // @grant none
  10. // ==/UserScript==
  11. /* jshint -W097 */
  12. 'use strict';
  13.  
  14. var pressedKeysTracking = {};
  15.  
  16. document.addEventListener('keydown', function(e) {
  17. pressedKeysTracking[e.which] = true;
  18. });
  19.  
  20. document.addEventListener('keyup', function(e) {
  21. delete pressedKeysTracking[e.which];
  22. });
  23.  
  24. function handlePasteEvent(e) {
  25. if (pressedKeysTracking[17] && pressedKeysTracking[16] && pressedKeysTracking[86]) {
  26. e.preventDefault();
  27. document.execCommand("insertHTML", false, decodeURI(e.clipboardData.getData("Text")));
  28. }
  29. };
  30.  
  31. Array.prototype.slice.call(document.querySelectorAll("div[contenteditable], input")).map(function(x){
  32. x.addEventListener("paste", handlePasteEvent);
  33. return x;
  34. });