Greasy Fork

钉钉web版审批链接改正

修改钉钉web版消息中错误的审批链接,默认情况下钉钉在待办消息中给出的审批链接是错误的,无法直接点击打开,需要到工作台中审批中找待审批列表,才能打开。此脚本自动检查并修正这些链接。

目前为 2018-07-04 提交的版本。查看 最新版本

// ==UserScript==
// @name         钉钉web版审批链接改正
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  修改钉钉web版消息中错误的审批链接,默认情况下钉钉在待办消息中给出的审批链接是错误的,无法直接点击打开,需要到工作台中审批中找待审批列表,才能打开。此脚本自动检查并修正这些链接。
// @author       easyt
// @match        https://im.dingtalk.com/*
// @grant        none
// ==/UserScript==

var replacenum=0;
window.setInterval(comp,5000);
function comp(){
    var nownum=$("div.msg-body a").length;
    if(replacenum!==nownum){ //说明屏幕上消息体方块数目变了,需要替换
        replacenum=nownum;
        rep(nownum-1);
           // alert("需要改. 原"+replacenum+" 现"+nownum);
    }
    else{
    }
}
//替换函数
function rep(inputnum){
    var myarray = $("div.msg-body a");
    for (var index = inputnum; index>0; index=index-1) {
        var myarrayindexhref = myarray[index].href;
        if(myarrayindexhref.indexOf("%2Fmobile%2Fhomepage")!=-1){ //含有审批的错误链接
            $("div.msg-body a")[index].href = myarrayindexhref.replace("%2Fmobile%2Fhomepage","%2Fpc%2Fquery%2Fpchomepage"); //替换改为正确的审批链接
            //alert("包含"+index+"\r\n"+$("div.msg-body a")[index].href);
        }
        else{
            //alert("不包含"+index);
        }
    }
}