列表格式显示

- 分类

广告招商中......
联系方式!

- 时间排序 更多...
    - 点击排序 更多...
      - 大小排序 更多...
        作者

         

        最近发布的软件 更多>>

        首页 >> >> >>开发Chrome插件获取当前页面Cookie 发布者:blog >> 本人发布的更多软件

        广告招商中...... 联系方式!

        开发Chrome插件获取当前页面Cookie 

        时间:2024-06-19 01:39:08      作者:blog     访问量:  
        ;开始下载地址

        https://cloud.tencent.com/developer/article/2376970

        开发Chrome插件获取当前页面Cookie


        Pasted image 20231230233809

        GitHub

        https://github.com/wenterwang/CookieTool

        manifest.json

        代码语言: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"
          }}

        hello.html

        插件的端面,前面介绍中有截图

        代码语言:javascript

        复制

        <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>

        popup.js

        代码语言:javascript

        复制

        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.');
                });
              });
            });
          });});

        发布至Google Store

        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插件开发之右键百度搜索选定词

        增加   


        相关评论        新窗口打开查看评论