【无用教程】清除GitHub幽灵通知

背景

有时你会收到一些来自GitHub不知名repo的钓鱼邮件,如果它的仓库被ban了,那你很有可能会遇到 Inbox 显示有消息,但是点进去以后空荡荡,然后那个右上角的提示点点始终显示就很难受……

另,虽然GitHub似乎尝试修复了,但事实上有时候还是会遇到这个破问题

解决方案

有以下几种办法清除它(来源:https://github.com/orgs/community/discussions/6874

  1. 使用命令行调用gh清除

    gh api /notifications -X GET | ConvertFrom-Json | ForEach-Object { gh api "/notifications/threads/$($_.id)" -X PATCH }
    
  2. 在浏览器控制台运行

    (function(){
      // Loop 1000 times
      for (let i = 0; i < 1000; i++) {
        var f = document.querySelector('.js-notifications-mark-all-actions form[action="/notifications/beta/mark"]');
        if (f) {
          fetch(f.action, {
            method: f.method,
            body: new FormData(f),
            credentials: "include"
          }).then(r => {
            if (r.ok) {
              // Only refresh the page after the last loop succeeds to avoid interruption midway
              if (i === 999) {
                setTimeout(() => location.reload(), 500);
              }
            }
          });
        }
      }
    })();
    
  3. 使用curl清除通知(本质上都是走的GitHub api)

    curl -X PUT
        -H "Accept: application/vnd.github.v3+json" \
        -H "Authorization: token $TOKEN" \
        https://api.github.com/notifications \
        -d '{"last_read_at":"2026-03-26T08:00:00Z"}'
    
1 个赞