// ==UserScript== // @name Flower Password // @namespace https://greasyfork.org/zh-CN/scripts/23026-flower-password // @version 0.5.1 // @description 花密 Flower Password --- 可记忆的密码管理方案 // @author 徐小花, Johnny Jian, xLsDg // @include http://* // @include https://* // @match http://*/* // @match https://*/* // @require https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js // @require https://cdn.jsdelivr.net/npm/fpcode/dist/flowerpassword.umd.js // @require https://cdn.jsdelivr.net/npm/punycode@1.4.1/punycode.min.js // @require https://cdn.jsdelivr.net/gh/gorhill/publicsuffixlist.js/publicsuffixlist.min.js // @grant GM_getResourceText // @grant GM_addStyle // @grant GM_setClipboard // @run-at document-end // @license MIT License // @encoding utf-8 // @homepageURL https://github.com/xlsdg/flower-password-user-script // @supportURL https://github.com/xlsdg/flower-password-user-script/issues // @icon https://cdn.jsdelivr.net/gh/xlsdg/flower-password-user-script/icon.png // @resource fpStyle https://cdn.jsdelivr.net/gh/xlsdg/flower-password-user-script/fp.min.css // @resource lstPublicSuffix https://publicsuffix.org/list/public_suffix_list.dat // @downloadURL none // ==/UserScript== (function () { 'use strict'; var currentField = null; function setupInputListeners() { function insideBox(e) { return e.parents('#flower-password-input').length > 0; } var lstPublicSuffix = GM_getResourceText('lstPublicSuffix'); publicSuffixList.parse(lstPublicSuffix, punycode.toASCII); var hostname = location.hostname.toLowerCase(); var domain = publicSuffixList.getDomain(hostname); var suffix = publicSuffixList.getPublicSuffix(hostname); $(document).on('focus', 'input:password', function () { if (insideBox($(this))) { return; } lazyInject(); if (currentField && currentField.get(0) != this) { $('#flower-password-password, #flower-password-key').val(''); } currentField = $(this); var offset = currentField.offset(); var height = currentField.outerHeight(); $('#flower-password-input') .css({ left: offset.left + 'px', top: offset.top + height + 'px', }) .show(); var code = ''; var key = domain.replace('.' + suffix, '') + code; $('#flower-password-key').val(key); }); $(document).on('focus', 'input:not(:password)', function () { if (insideBox($(this))) { return; } $('#flower-password-input').hide(); }); } function isInjected() { return $('#flower-password-input').length > 0; } function lazyInject() { if (isInjected()) { return; } var style = GM_getResourceText('fpStyle'); GM_addStyle(style); var html = ''; $('body').append(html); var onChange = function () { var password = $('#flower-password-password').val(); var key = $('#flower-password-key').val(); var result = fpCode(password, key); if (result) { currentField.val(result); GM_setClipboard(result); } }; $('#flower-password-password, #flower-password-key') .change(onChange) .keyup(onChange) .keyup(function (e) { if (e.which === 13 || e.which === 27) { currentField.focus(); $('#flower-password-input').hide(); } }); $('#flower-password-close').click(function () { $('#flower-password-input').hide(); }); } setupInputListeners(); })();