DisqusTimestampForumlink

Open disqus comment in the forum when its timestamp is clicked

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         DisqusTimestampForumlink
// @version      0.2
// @description  Open disqus comment in the forum when its timestamp is clicked
// @author       xy
// @match        https://disqus.com/*
// @namespace https://greasyfork.org/users/809293
// ==/UserScript==

(function() {
  'use strict';

  function threadUrl(threadId, hash) {
    const apiKey = 'tWtbL1OV8by298LctEFv9ccPxqJ7DUCg5sS064ItLBAWl11EdFJYcHqIgiZCVvS1';
    var link = 'https://disqus.com/home/discussion/';
    /* global $ */
    $.ajax({
      type: 'GET',
      dataType: 'json',
      url: 'https://disqus.com/api/3.0/threads/details.json',
      data: {
        api_key: apiKey,
        thread: threadId,
      },
      async: false,
      success: function(data) {
        var r = data.response;
        link += r.forum + '/' + r.slug + '/' + hash;
      }});
    return link;
  }

  document.addEventListener('click', (event) => {
    const validPaths = ['/home/inbox/', '/by/'];
    const validClasses = ['card-comment-truncated', 'link-gray time'];
    var clicked = event.target;
    if (validPaths.some(s => window.location.href.includes(s))
        && validClasses.some(s => clicked.className.includes(s))) {
      clicked.href = threadUrl(clicked.dataset.threadId, clicked.hash);
    }});
})();