列表格式显示
广告招商中...... 联系方式!
私信 +好友
https://cloud.tencent.com/developer/article/2376970
开发Chrome插件获取当前页面Cookie
Pasted image 20231230233809
https://github.com/wenterwang/CookieTool
代码语言:javascript
复制
{ "manifest_version": 3, "name": "Cookie Tool", "version": "0.0.1", "author": "wenterwang", "permissions": [ "cookies" ], "host_permissions": [ "http://*/*", "https://*/*" ], "action": { "default_title": "Get Current Page Cookies", "default_popup": "hello.html", "default_icon": "icon.png" }}
插件的端面,前面介绍中有截图
<html> <head> <title>Get Current Page Cookies</title> <meta charset="UTF-8"> <script src="popup.js"></script> <style> body { font-family: Arial, sans-serif; margin: 0; padding: 0; min-width: 200px; } ul { list-style: none; padding: 0; } li { padding: 10px; border-bottom: 1px solid #ddd; } li:last-child { border-bottom: none; } #toast { display: none; position: fixed; bottom: 10px; left: 50%; transform: translateX(-50%); background-color: #333; color: #fff; padding: 5px 10px; border-radius: 5px; white-space: nowrap; /* 添加此行以保持 toast 文本在一行显示 */ } </style> </head> <body> <ul> <li id="get-cookies">Get Cookies</li> </ul> <ul> <li id="get-other">Todo</li> </ul> <div id="toast"></div> </body></html>
document.addEventListener('DOMContentLoaded', function() { var getButton = document.getElementById('get-cookies'); var toast = document.getElementById('toast'); function showToast(message) { toast.textContent = message; toast.style.display = 'block'; setTimeout(function() { toast.style.display = 'none'; }, 2000); } getButton.addEventListener('click', function() { chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { var url = tabs[0].url; chrome.cookies.getAll({url: url}, function(cookies) { let cookiesText = ''; for (var i = 0; i < cookies.length; i++) { var cookie = cookies[i]; cookiesText += cookie.name + '=' + cookie.value + (i < cookies.length - 1 ? '; ' : ''); } // 将获取到的 cookie 复制到剪切板 navigator.clipboard.writeText(cookiesText).then(function() { showToast('Cookies copied to clipboard.'); }, function(err) { console.error('Could not copy cookies to clipboard: ', err); showToast('Failed to copy cookies to clipboard.'); }); }); }); });});
https://developer.chrome.com/docs/webstore/publish?hl=zh-cn
chrome扩展示例 https://github.com/GoogleChrome/chrome-extensions-samples
本页Html网址:/htmlsoft/619358.html
本页aspx网址:/soft.aspx?id=619358&bianhao=202406190139084367_54791&kind1=&kind2=
最后访问时间:
上一篇:Selenium 系列篇(六):反反爬篇
下一篇:01 chrome插件开发之右键百度搜索选定词
增加