密码生成器

一个自用的脚本,所生成的密码仅建议作为实际密码的组成部分使用

目前為 2017-03-12 提交的版本,檢視 最新版本

// ==UserScript==
// @name        密码生成器
// @namespace   wdssmq
// @description 一个自用的脚本,所生成的密码仅建议作为实际密码的组成部分使用
// @include     http://*
// @include     https://*
// @exclude     http://t.qq.com/*
// @version     1
// @grant       none
// ==/UserScript==
(function () {
	'use strict';
	var host = window.location.host;
	var hash = window.location.hash.indexOf("www") > -1 ? window.location.hash.replace(/#/g, "") : ""
		var strHash = fnGetHash(host, 65537);
	if (hash !== "")
		strHash += " - " + fnGetHash(hash, 65537);
	if ($n("input[type=password]") || parseInt(GetCookie(host)) < 4 || hash !== "") {
		var domH2 = fnAdd(strHash);
    SetCookie(host, parseInt(GetCookie(host))+1, 180);
		// $n("input[type=password]").addEventListener('blur', function () {
			// if ($n("input[type=password]").value.length > 13)
				// SetCookie(host, host, 180);
		// });
	}
	function fnGetHash(host, i) {
		host = host.replace(/[^\.]*\.?([^\.]+\.[^\.]+)/g, "$1");
		i = parseInt(i);
		var intHost = parseInt(host, 36);
		var daysStamp = parseInt((new Date).getTime() / (1000 * 60 * 60 * 24));
		var result = "";
		result = parseInt((daysStamp + (intHost % 181)) / 181);
		result = result + i + intHost;
		result = result * 181;
		return host + " - " + result.toString(36);
	}
	function $n(e) {
		return document.querySelector(e);
	}
	function $na(e) {
		return document.querySelectorAll(e);
	}
	function fnAdd(text) {
		var h2 = document.createElement('h2');
		var textnode = document.createTextNode(text);
		h2.appendChild(textnode);
		h2.setAttribute('style', "background-color: rgb(252, 248, 227); border: 1px solid rgb(250, 235, 204); border-radius: 4px; padding: 5px; z-index: 1060; margin: 0px auto; position: fixed; bottom: 0px; width: 100%; font-size: 15px; line-height: 1.2em; text-align: center;");
		$n("body").insertBefore(h2, $n("body").childNodes[0]);
		return h2;
	}
	function SetCookie(sName, sValue, iExpireDays) {
		var path = (typeof(cookiespath) == "undefined") ? "/" : cookiespath;
		if (iExpireDays) {
			var dExpire = new Date();
			dExpire.setTime(dExpire.getTime() + parseInt(iExpireDays * 24 * 60 * 60 * 1000));
			document.cookie = sName + "=" + escape(sValue) + "; expires=" + dExpire.toGMTString() + "; path=" + path;
		} else {
			document.cookie = sName + "=" + escape(sValue) + "; path=" + path;
		}
	}
	function GetCookie(sName) {
		var arr = document.cookie.match(new RegExp("(^| )" + sName + "=([^;]*)(;|$)"));
		if (arr != null) {
			return unescape(arr[2]);
		};
		return 0;
	}
})();