Advertisement
Guest User

Untitled

a guest
Feb 27th, 2022
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.08 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Master Password+
  3. // @author xiaoxiaoflood
  4. // @include *
  5. // @startup masterPasswordPlus
  6. // @shutdown UC.masterPasswordPlus.destroy();
  7. // @onlyonce
  8. // ==/UserScript==
  9.  
  10. _ucUtils.sharedGlobal.masterPasswordPlus = {
  11. _startup: function (win) {
  12. if (!win.isChromeWindow || win != win.top)
  13. return;
  14.  
  15. let document = win.document;
  16. if (document.getElementsByTagName('keyset').length) {
  17. let key = document.getElementById('mpPk');
  18. if (key) {
  19. this.atalho(key);
  20. } else {
  21. let k = _ucUtils.createElement(document, 'key', {id: 'mpPk'});
  22. this.atalho(k);
  23. document.getElementsByTagName('keyset')[0].appendChild(k);
  24. }
  25. }
  26. let ovl = _ucUtils.createElement(document, 'div', {
  27. id: 'mpPlus',
  28. style: 'position: fixed; display: none; width: 100%; height: 100%; top: 0; background-color: gray; z-index: 2; cursor: pointer;'
  29. },true);
  30. document.documentElement.appendChild(ovl);
  31.  
  32. let input = _ucUtils.createElement(document, 'input', {
  33. id: 'mpPinput',
  34. type: 'password',
  35. style: 'border: 1px solid black; text-align: center; position: absolute; top:0; bottom: 0; left: 0; right: 0; margin: auto;'
  36. }, true);
  37. ovl.appendChild(input);
  38.  
  39. input.addEventListener('blur', function () {
  40. setTimeout(() => {
  41. input.focus();
  42. });
  43. });
  44. win.addEventListener('activate', function () {
  45. input.focus();
  46. });
  47.  
  48. if (this.mp.hasPassword && this.locked) {
  49. this.lock(document, win);
  50. }
  51. },
  52.  
  53. mp: Cc['@mozilla.org/security/pk11tokendb;1'].getService(Ci.nsIPK11TokenDB).getInternalKeyToken(),
  54.  
  55. keydownFunc: function (e) {
  56. let input = this.document.getElementById('mpPinput');
  57. if (e.key == 'Enter') {
  58. if (_ucUtils.sharedGlobal.masterPasswordPlus.mp.checkPassword(input.value)) {
  59. _ucUtils.windows.forEach((doc, win) => {
  60. doc.getElementById('mpPinput').value = '';
  61. doc.getElementById('mpPlus').style.display = 'none';
  62. win.titObs.disconnect();
  63. doc.title = win.titulo;
  64. win.removeEventListener('keydown', _ucUtils.sharedGlobal.masterPasswordPlus.keydownFunc, true);
  65. win.addEventListener('AppCommand', HandleAppCommandEvent, true);
  66. }, false);
  67. _ucUtils.sharedGlobal.masterPasswordPlus.locked = false;
  68. } else {
  69. input.value = '';
  70. }
  71. } else if ((e.key.length > 2 && // teclas digitáveis quase sempre =1, exceto acento seguido de char não acentuável, aí =2.
  72. e.code.length == 2 && // F1 a F9 possuem key.length =2, mas são as únicas com code.length = 2, demais são > (como KeyA).
  73. e.key != 'Dead' && // teclas de acento, que aguardam a tecla seguinte
  74. e.key != 'Backspace' && e.key != 'Delete' && e.key != 'ArrowLeft' && e.key != 'ArrowRight' && e.key != 'Home' && e.key != 'End') || e.altKey || (e.ctrlKey && e.code != 'KeyA')) {
  75. e.preventDefault();
  76. }
  77. },
  78.  
  79. atalho: function (el) {
  80. el.setAttribute('oncommand', '_ucUtils.sharedGlobal.masterPasswordPlus.lockAll();');
  81. el.setAttribute('modifiers', 'accel alt shift');
  82. el.setAttribute('key', 'W');
  83. },
  84.  
  85. onTitleChanged: function (win) {
  86. let document = win.document;
  87. let observer = new MutationObserver(mutationsList => {
  88. if (mutationsList[0].oldValue !== document.title && document.title != '🞻🞻🞻🞻🞻🞻') {
  89. win.titulo = document.title;
  90. document.title = '🞻🞻🞻🞻🞻🞻';
  91. }
  92. });
  93.  
  94. if (document.getElementsByTagName('title').length)
  95. observer.observe(document.getElementsByTagName('title')[0], { childList: true, characterData: true });
  96. else
  97. observer.observe(document.documentElement, { attributeFilter: ['title'], attributeOldValue: true });
  98.  
  99. return observer;
  100. },
  101.  
  102. lock: function (doc, win) {
  103. win.addEventListener('keydown', _ucUtils.sharedGlobal.masterPasswordPlus.keydownFunc, true);
  104. let input = doc.getElementById('mpPinput');
  105. input.value = '';
  106. doc.getElementById('mpPlus').style.display = 'block';
  107. win.titulo = doc.title;
  108. doc.title = '🞻🞻🞻🞻🞻🞻';
  109. win.titObs = this.onTitleChanged(win);
  110. win.removeEventListener('AppCommand', HandleAppCommandEvent, true);
  111. input.focus();
  112. },
  113.  
  114. lockAll: function () {
  115. if (!_ucUtils.sharedGlobal.masterPasswordPlus.mp.hasPassword)
  116. return;
  117.  
  118. this.locked = true;
  119. _ucUtils.windows.forEach((doc, win) => {
  120. this.lock(doc, win);
  121. }, false);
  122. },
  123.  
  124. locked: true,
  125.  
  126. destroy: function () {
  127. _ucUtils.windows.forEach((doc) => {
  128. let mpPlus = doc.getElementById('mpPlus');
  129. if (mpPlus) {
  130. doc.getElementById('mpPlus').remove();
  131. }
  132. let mpPk = doc.getElementById('mpPk');
  133. if (mpPk) {
  134. mpPk.setAttribute('modifiers', '');
  135. mpPk.setAttribute('oncommand', '');
  136. mpPk.setAttribute('key', '');
  137. }
  138. }, false);
  139. delete _ucUtils.sharedGlobal.masterPasswordPlus;
  140. }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement