用于指示 Stack Exchange 问题何时安排自动删除的用户脚本或扩展名

软件推荐 铬合金 堆栈交换
2021-10-12 03:05:04

Stack Exchange 上的问题受自动删除规则的约束,这对于大多数人来说有点太复杂而难以记住。我想知道我正在查看的问题是否计划删除,因为我可能想保存它或避免浪费我的关闭/删除投票。

我正在寻找一个用户脚本或浏览器扩展:

  1. 如果计划删除问题,则向 Stack Exchange 问题页面添加视觉指示*。
  2. 指示(大约)计划删除的时间
  3. 在 Chrome 中工作。

通过 Stack Apps 搜索并没有找到任何相关信息。


* 我了解如果没有任何问题,每个新问题都有资格在 365 天内删除。如果只检查 9 天和 30 天规则,那很好。

1个回答

我为此制作了一个用户脚本。我已经在Franck 的有用查询中显示的几个问题上对其进行了测试,并且它有效,因此它应该适用于其余问题:)

要安装,请先安装Tampermonkey,然后安装脚本

// ==UserScript==
// @name         Will question be deleted?
// @namespace    http://stackexchange.com/users/4337810/%E1%94%95%E1%96%BA%E1%98%8E%E1%95%8A
// @version      1.2
// @description  Adds a message on questions which *might* be deleted by the SE delete bot
// @author       ᔕᖺᘎᕊ (http://stackexchange.com/users/4337810/%E1%94%95%E1%96%BA%E1%98%8E%E1%95%8A)
// @match        *://*.stackexchange.com/*
// @match        *://*.stackoverflow.com/*
// @match        *://*.superuser.com/*
// @match        *://*.serverfault.com/*
// @match        *://*.askubuntu.com/*
// @match        *://*.stackapps.com/*
// @match        *://*.mathoverflow.net/*
// @grant        none
// ==/UserScript==
function addWarning(title) {
    if (! $('#riskOfDeletion').length ) {
        $('#qinfo').append("<tr><td><p class='label-key' id='riskOfDeletion'>Risk of <br />deletion?</p></td><td style='padding-left:10px'><p class='label-key' title='"+title+"'><b>Yes</b></p></td></tr>");    
    }
}

var askedDaysAgo = $('.question-stats td:eq(1) p').text().split(' ')[0],
    voteCount = $('.vote-count-post').text(),
    answerCount = $('#answers-header div h2').text().split(' ')[0],
    id = $(location).attr('href').split('/')[4],
    sitename = $(location).attr('hostname').split('.')[0],
    currentTime = (new Date).getTime(),
    elevenMonths = 28927183,
    nineDays = 777600,
    fifteenDays = 1296000,
    commentCount = $('.question .comment').length;

//More than 30 days old:
if( voteCount <= -1 ) { //if the vote count is <= -1
    if( answerCount.trim() == '' ) { //if there are no answers
        $.getJSON("https://api.stackexchange.com/2.2/questions/" + id + "?order=desc&sort=activity&site=" + sitename, function(json) {
            if( !json.items[0].locked_date ) { //if it isn't locked
                if ( currentTime - json.items[0].creation_date >= fifteenDays ) { //only care if it will happen in the next 15 days
                    addWarning('Within 15 days');
                }
            }
        });
    }
}

//More than 365 days old:
$.getJSON("https://api.stackexchange.com/2.2/questions/" + id + "?order=desc&sort=activity&site=" + sitename, function(json) {
    var creationDate = json.items[0].creation_date,
        score = json.items[0].score,
        answers = json.items[0].answer_count,
        views = json.items[0].view_count;

    if( currentTime - creationDate <= elevenMonths ) { //If it's been at least 11 months (we don't care about questions newer than that, yet...)
        if( answers == 0 ) { //if there aren't any answers
            if( !json.items[0].locked_date ) { //if it is not locked
                if( views <= (Math.floor(currentTime/8.64e7) * 1.5)) { //if view count <= the age of the question in days times 1.5
                    if( commentCount <= 1 ) { //if there are 1 or 0 comments
                        addWarning('Within a month');
                    }
                }
            }            
        }        
    }    
});

//More than 9 days since closure:
$.getJSON("https://api.stackexchange.com/2.2/questions/" + id + "?order=desc&sort=activity&site=" + sitename, function(json) {
    if( json.items[0].closed_date ) { //if the question is closed
        var closedDate = json.items[0].closed_date,
            closedReason = json.items[0].closed_reason,
            score = json.items[0].score,
            answers = json.items[0].answer_count;

        if( closedReason != 'duplicate' ) { //if it's not been closed as a duplicate
            if( score <= 0 ) { //if the score is less than or equal to 0
                if( !json.items[0].locked_date ) { //if it is not locked
                    if( answerCount == 0 ) { //if it has 0 answers
                        if (!json.items[0].accepted_answer_id) { //if it has no accepted answer
                            addWarning('Within 9 days');
                        }
                    }
                }
            }
        }
    }
});

如果存在删除风险,请在下面指定的时间内,您应该看到以下内容:

在此处输入图像描述

滚动上面将显示它何时可能被删除。

以下是它的工作原理:

  1. 如果问题超过 30 天,并且...

    • 得分为 -1 或更低
    • 没有答案
    • 未锁定

仅开始检查其分数是否小于或等于 -1


  1. 如果问题超过 365 天,并且...

    • 得分为 0,如果所有者被删除,则得分为 1
    • 没有答案
    • 未锁定
    • 查看次数 <= 问题的年龄(以天为单位)乘以 1.5
    • 有 1 或 0 条评论

仅开始检查自提出问题以来是否至少 11 个月


  1. 如果问题在 9 天前关闭,并且...

    • 不作为重复关闭
    • 得分为 0 或更低
    • 未锁定
    • 没有得分 > 0 的答案
    • 没有接受的答案
    • 没有待决的重新开放投票
    • 过去 9 天内未编辑

仅开始检查问题是否已关闭