VK Comments Link

Add a link to comments on the Vk search

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         VK Comments Link
// @namespace    http://alamote.pp.ua/
// @match        https://vk.com/search*
// @grant        none
// @version      1.1
// @description  Add a link to comments on the Vk search
// @icon         http://alamote.pp.ua/staff/alamote-logo.png
// @license      MIT
// ==/UserScript==

/*jshint esversion: 6 */

const setButtons = () => {
    const results = document.querySelectorAll('.groups_row:not(.with-comments)');
    for (let i = 0; i < results.length; i++) {
        const row = results.item(i);
        row.classList.add('with-comments');
        console.log(row.dataset.id);
        const subBtn = row.querySelector('.search_sub_button');
        if (subBtn) {
            subBtn.removeAttribute('onclick');
            subBtn.classList.add('comments-btn');
            subBtn.classList.remove('search_sub_button');
            subBtn.querySelector('span.FlatButton__content').innerHTML = 'Комментарии';
            subBtn.addEventListener('click', () => {
                const handle = window.open(`https://vk.com/wall-${row.dataset.id}?q=type%3Areply`);
                handle.blur();
                window.focus();
            });
        }
        const unsubBtn = row.querySelector('.search_unsub_button');
        if (unsubBtn) {
            unsubBtn.remove();
        }
    }
}


(function() {
    'use strict';

    setButtons();
    setInterval(setButtons, 1000);

})();