您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Generate random passwords with Context Menu
当前为
- // ==UserScript==
- // @name Password Generator
- // @name:tr Şifre Oluşturucu
- // @namespace http://tampermonkey.net/
- // @version 0.2
- // @description Generate random passwords with Context Menu
- // @description:tr Sağ tık menüsünü kullanarak rastgele şifreler oluşturun
- // @author Muhammed Aktolu
- // @match *://*/*
- // @icon https://static-00.iconduck.com/assets.00/security-password-icon-1959x2048-sq0rdvok.png
- // @grant GM_registerMenuCommand
- // @grant GM_setValue
- // @grant GM_getValue
- // ==/UserScript==
- (function() {
- 'use strict';
- const generatePasswordForContextMenu = function(length = 16, minPerType = 2, uppercase = true, lowercase = true, number = true, symbol = false) {
- let string = '';
- let pass = {
- uppercase: true,
- lowercase: true,
- number: true,
- symbol: true,
- }
- let match;
- if (uppercase) {
- string += 'ABCDEFGHJKMNPQRSTUVWXYZ';
- }
- if (lowercase) {
- string += 'abcdefghjkmnpqrstuvwxyz';
- }
- if (number) {
- string += '23456789';
- }
- if (symbol) {
- string += '!";#$%&\'()*+,-./:;<=>?@[]^_`{|}~';
- }
- let password = Array.from(crypto.getRandomValues(new Uint32Array(length)))
- .map((x) => string[x % string.length])
- .join('');
- if (uppercase) {
- match = password.match(/[A-Z]/g);
- if (!match || match.length < minPerType) {
- pass.uppercase = false;
- }
- }
- if (lowercase) {
- match = password.match(/[a-z]/g);
- if (!match || match.length < minPerType) {
- pass.lowercase = false;
- }
- }
- if (number) {
- match = password.match(/\d/g);
- if (!match || match.length < minPerType) {
- pass.number = false;
- }
- }
- if (symbol) {
- match = password.match(/[^A-Za-z0-9]/g);
- if (!match || match.length < minPerType) {
- pass.symbol = false;
- }
- }
- if (password.match(/(.)\1/) || !pass.uppercase || !pass.lowercase || !pass.number || !pass.symbol) {
- return generatePasswordForContextMenu(length, minPerType, uppercase, lowercase, number, symbol);
- } else {
- return password;
- }
- }
- function multilineCssForContextMenu(css) {
- let el = document.createElement('style');
- el.appendChild(document.createTextNode(css));
- document.head.appendChild(el);
- return el;
- }
- GM_registerMenuCommand('Generate Password', () => {
- //let length = GM_getValue('passwordGeneratorLength', '16');
- let password = generatePasswordForContextMenu(GM_getValue('pgLength', 16), GM_getValue('pgMinPerType', 2), GM_getValue('pgUppercase', true), GM_getValue('pgLowercase', true), GM_getValue('pgNumber', true), GM_getValue('pgSymbol', false));
- // language=css
- let styleString = `
- .myTmBlock {
- position: fixed !important;
- width: 100vw !important;
- height: 100vh !important;
- z-index: 999999999 !important;
- display: flex !important;
- align-items: center !important;
- justify-content: center !important;
- background-color: rgba(0, 0, 0, .9) !important;
- left: 0 !important;
- top: 0 !important;
- }
- .myTmBlock * {
- font-family: Helvetica, Arial, sans-serif !important;
- font-size: 15px !important;
- font-weight: 300 !important;
- letter-spacing: 0 !important;
- line-height: 100% !important;
- color: whitesmoke !important;
- float: none !important;
- border-radius: 0 !important;
- }
- .myTmBlock div {
- display: block !important;
- }
- .myTmBlock button {
- background-color: red !important;
- padding: 10px 30px !important;
- border: none !important;
- cursor: pointer !important;
- }
- .myTmBlock input {
- margin-inline: 0 !important;
- font-size: 13px !important;
- display: inline !important;
- }
- .myTmBlock input[type="number"] {
- background-color: black !important;
- border: 1px solid whitesmoke !important;
- width: 60px !important;
- padding: 1px 0 1px 2px !important;
- appearance: auto !important;
- }
- .myTmBlock label {
- margin-right: 15px !important;
- cursor: pointer !important;
- -webkit-user-select: none !important;
- user-select: none !important;
- }
- .myTmBox {
- text-align: center !important;
- }
- #myTmPassword {
- font-size: 3rem !important;
- margin-bottom: 15px !important;
- }
- `;
- let style = multilineCssForContextMenu(styleString);
- let block = document.createElement('div');
- block.classList.add('myTmBlock');
- document.body.appendChild(block);
- // language=html
- block.innerHTML = `<div class="myTmBox">
- <div id="myTmPassword"></div>
- <div>
- <button id="myTmCopyPassword">Copy</button>
- <button id="myTmCancelPassword">Cancel</button>
- </div>
- <div style="margin-top: 100px">
- <div>
- Length: <input id="myTmPasswordLength" type="number" value="`+GM_getValue('pgLength', 16)+`" style="margin-right: 60px" min="8" max="64">
- Min Chars Per Type: <input id="myTmPasswordMinPerType" type="number" value="`+GM_getValue('pgMinPerType', 2)+`" min="0">
- </div>
- <div style="margin-top: 10px">
- <label>Uppercase: <input id="myTmUppercase" type="checkbox"`+(GM_getValue('pgUppercase', true) ? ' checked' : '')+`></label>
- <label>Lowercase: <input id="myTmLowercase" type="checkbox"`+(GM_getValue('pgLowercase', true) ? ' checked' : '')+`></label>
- <label>Number: <input id="myTmNumber" type="checkbox"`+(GM_getValue('pgNumber', true) ? ' checked' : '')+`></label>
- <label>Symbol: <input id="myTmSymbol" type="checkbox"`+(GM_getValue('pgSymbol', false) ? ' checked' : '')+`></label>
- </div>
- <button id="myTmReGeneratePassword" style="margin-top: 25px">Regenerate Password</button>
- </div>
- </div>`;
- let passwordDiv = document.getElementById('myTmPassword');
- let copyButton = document.getElementById('myTmCopyPassword');
- let cancelButton = document.getElementById('myTmCancelPassword');
- let passwordLengthInput = document.getElementById('myTmPasswordLength');
- let minPerTypeInput = document.getElementById('myTmPasswordMinPerType');
- let uppercaseCheckBox = document.getElementById('myTmUppercase');
- let lowercaseCheckBox = document.getElementById('myTmLowercase');
- let numberCheckBox = document.getElementById('myTmNumber');
- let symbolCheckBox = document.getElementById('myTmSymbol');
- let reGenerateButton = document.getElementById('myTmReGeneratePassword');
- passwordDiv.innerText = password;
- copyButton.addEventListener('click', () => {
- navigator.clipboard.writeText(password);
- block.remove();
- style.remove();
- });
- cancelButton.addEventListener('click', () => {
- block.remove();
- style.remove();
- });
- [passwordLengthInput, minPerTypeInput].forEach(item => {
- item.addEventListener('click', () => {
- item.select();
- });
- });
- reGenerateButton.addEventListener('click', function() {
- GM_setValue('pgLength', parseInt(passwordLengthInput.value));
- GM_setValue('pgMinPerType', parseInt(minPerTypeInput.value));
- GM_setValue('pgUppercase', uppercaseCheckBox.checked);
- GM_setValue('pgLowercase', lowercaseCheckBox.checked);
- GM_setValue('pgNumber', numberCheckBox.checked);
- GM_setValue('pgSymbol', symbolCheckBox.checked);
- password = generatePasswordForContextMenu(parseInt(passwordLengthInput.value), parseInt(minPerTypeInput.value), uppercaseCheckBox.checked, lowercaseCheckBox.checked, numberCheckBox.checked, symbolCheckBox.checked);
- passwordDiv.innerText = password;
- });
- });
- })();