dtruebin / Remove Instagram Reposts from VK Feed

// ==UserScript==
// @name Remove Instagram Reposts from VK Feed
// @description Hides all automatic Instagram->VK reposts from your VK news feed.
// @author dtruebin
// @version 1.0.2
// @include https://vk.com/*
// @require https://code.jquery.com/jquery-1.12.4.min.js
// ==/UserScript==

function removeInstagramReposts(){
    // By default, hides only post's content while leaving the actual post and footer with comments intact.
    $("a.wall_post_source_icon.wall_post_source_instagram").closest("div.published_sec_quote,div.copy_quote,div.feed_row").find("div.wall_post_text,div.page_post_sized_thumbs").remove();

    // Uncomment to hide the post containing an Instagram repost completely:
    //$("a.wall_post_source_icon.wall_post_source_instagram").parents("div.feed_row").remove();
}

(function() {
    'use strict';
    var isLoaded = false;
    console.log("starting");

    window.addEventListener("load", function (event) {
        if (!isLoaded) {
            isLoaded = true;
            console.log("window.load", event);
            onChange();
            wrap3.addEventListener("DOMSubtreeModified", function (event) {
                onChange();
            });
        }
    });

    var isChangingNow = false;
    var isAllowedToRunScript = false;
    var lastTimeOut;

    function onTimeOut() {
        lastTimeOut = undefined;
        isChangingNow = false;
        isAllowedToRunScript = window.location.pathname == "/feed";
        console.log("updated", isAllowedToRunScript);

        removeInstagramReposts();
    }
    function onChange() {
        isChangingNow = true;
        isAllowedToRunScript = false;
        if (lastTimeOut) {
            clearTimeout(lastTimeOut);
        }
        lastTimeOut = setTimeout(onTimeOut, 1000);
    }
})();