sobclear

添加一个一键已读按钮

当前为 2022-02-20 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         sobclear
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  添加一个一键已读按钮
// @author       You
// @match        https://www.sunofbeach.net/
// @icon         https://www.google.com/s2/favicons?domain=sunofbeach.net
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';



let cssStr = `
        #clear-msg{
            color: #0084ff;
            margin-right: 12px !important;
        }
    `;
/**
 * 添加css样式
 * @returns {boolean}
 */
function initCss() {

    let addTo = document.querySelector('body');
    if (!addTo)
        addTo = (document.head || document.body || document.documentElement);


    //创建style标签
    let cssNode = document.createElement("style");
    cssNode.setAttribute("type", "text/css");



    //设置css值
    cssNode.innerHTML = cssStr;
    try {
        addTo.appendChild(cssNode);
    } catch (e) {
        console.log(e.message);
    }


}

/**
 * 获取cookie值
 * @param name
 * @returns {string|null}
 */
function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg))
        return unescape(arr[2]);
    else
        return null;
}

/**
 * 发送请求清除消息
 */
function clearMsg() {
    // https://api.sunofbeaches.com/ct/msg/read



    fetch('https://api.sunofbeaches.com/ct/msg/read',{
        headers:{
            'sob_token':getCookie('sob_token')
        }
    })
        .then(response => {

            console.log(response)
            let ring =document.querySelector('.el-badge__content')
            ring.style.display="none"
            alert("已读成功")
        })
        .then(data => console.log(data));

}

//创建节点
let clsBtnParent = document.getElementById('header-login-success');
let newnode = document.createElement("i");



//设置id
newnode.setAttribute('id', 'clear-msg')
newnode.setAttribute('class', 'el-icon-delete')


//添加到节点中
clsBtnParent.insertBefore(newnode, clsBtnParent.firstChild);


//初始化样式
initCss();

//添加点击事件
setTimeout(() => {
    newnode.onclick = function () {
        clearMsg()
    }
}, 1000)







})();