// ==UserScript==
// @name copyCookie
// @namespace copyCookie
// @version 0.1.2
// @author everstu
// @description 一键复制网站的cookie,支持字符串,json。
// @grant GM_registerMenuCommand
// @grant GM_setClipboard
// @match *://*/*
// @exclude *://192.*
// @run-at document-end
// @license MIT
// @require https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.5.1/jquery.min.js
// @downloadURL https://update.greasyfork.icu/scripts/431404/copyCookie.user.js
// @updateURL https://update.greasyfork.icu/scripts/431404/copyCookie.meta.js
// ==/UserScript==
(function () {
"use strict";
function MyTools() {
this.cjVersion = '0.1.0';
this.htmlCode = {
show: "
显
",
hidden: "隐藏插件
",
cjversion: "copyCookie
当前版本:" + this.cjVersion + "
",
copycookie: "复制成文本
",
copycookiejson: "复制成JSON
",
d_container_start: "",
d_container_end: "
",
};
}
MyTools.prototype.getCookiesStr = function () {
return document.cookie;
};
MyTools.prototype.getCookieObj = function () {
let cookieObj = {};
let cookieStr = this.getCookiesStr();
let pairList = cookieStr.split(';');
for (var _i = 0, pairList_1 = pairList; _i < pairList_1.length; _i++) {
let pair = pairList_1[_i];
let _a = pair.trim().split('='), key = _a[0], value = _a[1];
cookieObj[key] = value;
}
return cookieObj;
};
MyTools.prototype.getCookiesJson = function () {
let cookieObj = this.getCookieObj();
return JSON.stringify(cookieObj);
};
MyTools.prototype.copyCookieJson = function () {
let cookieJson = this.getCookiesJson();
GM_setClipboard(cookieJson, {type: 'text', mimetype: 'text/plain'});
};
MyTools.prototype.copyCookieString = function () {
GM_setClipboard(this.getCookiesStr(), {type: 'text', mimetype: 'text/plain'});
};
MyTools.prototype.copyString = function (type, obj) {
let oldHtml = '';
let domObj = $(obj);
if (domObj.data('can') === 'no') {
return;
}
if (type === 'json') {
this.copyCookieJson();
oldHtml = '复制成JSON';
} else {
this.copyCookieString();
oldHtml = '复制成文本';
}
domObj.data('can', 'no');
domObj.css('background', '#0C986C');
domObj.html('复制成功');
setTimeout(function () {
domObj.data('can', 'yes');
domObj.html(oldHtml);
domObj.css('background', '#CD0B02');
}, 300);
};
MyTools.prototype.initTools = function () {
let html = '';
let obj = this;
html += this.htmlCode.show;
html += this.htmlCode.d_container_start;
// html += this.htmlCode.hidden;
html += this.htmlCode.cjversion;
html += this.htmlCode.copycookie;
html += this.htmlCode.copycookiejson;
html += this.htmlCode.d_container_end;
$('body').append(html);
$('#copycookie').click(function () {
obj.copyString('string', this);
});
$('#copycookiejson').click(function () {
obj.copyString('json', this);
});
$('#d_container').mouseleave(function () {
$(this).hide();
$('#show').show();
});
$('#show').hover(function () {
$(this).hide();
$('#d_container').show();
});
};
MyTools.prototype.request = function () {
$.ajax({
type: "get",
async: false,
url: '',
dataType: "text",
xhrFields: {
withCredentials: true
},
success: function (res) {
console.log(this);
},
error: function (res) {
}
});
}
setTimeout(function () {
let tools = new MyTools();
tools.initTools();
}, 100);
})();