chrome插件获取网站Cookie清空网站cookie和复制cookie,jq/js复制内容到剪切板
写的一个插件可以自动获取网站的cookie和清空,还有复制功能,本文具体讲解怎么获取和清空和删除
本插件用到了jq增强:先将jq下载到本地,然后引入到页面中,就可以使用jq了
获取cookie并显示到页面上的教程:https://xiaoshen.blog.csdn.net/article/details/128455850
然后就是复制cookie的功能:
//点击后进行复制功能 $(‘#copyCookie’).click(function () { $(‘#hide’).val(document.getElementById(“cookies”).innerText);//把要复制的内容给到这里 $(‘#hide’).select(); try { var state = document.execCommand(‘copy’); } catch (err) { var state = false; } console.log(‘state—-‘, state); if (state) { $(“#copyCookie”).text(‘Cookie已复制’) }else{ $(“#copyCookie”).text(‘Cookie复制失败’) } })
清空网站Cookie功能:要在这个地方添加两个变量,清空cookie的时候有用
显示和清空网站cookie的代码:
// 当前激活的tabUrl let tabUrl = null let tabCookies = null // 获取网站的cookie,并打印出来 function handleCookie() { chrome.tabs.query({ active: true, lastFocusedWindow: true }, tabs => { let url = tabUrl || tabs[0].url; tabUrl = url; // use `url` here inside the callback because it’s asynchronous! console.log(‘url–‘, url); chrome.cookies.getAll({ url }, function (cookies) { console.log(‘得到的Cookie是:’, cookies); tabCookies = cookies; const resList = cookies.map(item => { return `${item.name}=${item.value}` }) const cookieStr = resList.join(“;”) console.log(“cookies—–“, cookieStr); document.getElementById(“cookies”).innerHTML = cookieStr document.getElementById(“useragent”).innerHTML = navigator.userAgent }); }); } // 清空网站的Cookie function removeCookie() { console.log(‘removeCookieurl–‘, tabUrl, tabCookies); tabCookies.forEach(item => { console.log(‘removeCookie删除的Cookie:’, item.name); chrome.cookies.remove({ url: tabUrl, name: item.name }) }); // 回显cookie为空 handleCookie() }
清空和复制按钮绑定事件:
// 清空cookie const removeCookitBtn = document.getElementById(“removeCookie”) removeCookitBtn.onclick = removeCookie //点击后进行复制功能 $(‘#copyCookie’).click(function () { $(‘#hide’).val(document.getElementById(“cookies”).innerText);//把要复制的内容给到这里 $(‘#hide’).select(); try { var state = document.execCommand(‘copy’); } catch (err) { var state = false; } console.log(‘state—-‘, state); if (state) { $(“#copyCookie”).text(‘Cookie已复制’) }else{ $(“#copyCookie”).text(‘Cookie复制失败’) } })