brabidou / Accelo Fix 'a tags' to be links in addition to the popup.

// ==UserScript==
// @name         Accelo Fix 'a tags' to be links in addition to the popup.
// @namespace    http://rabidou.io
// @version      0.7
// @description  Accelo tries to open everything in a popup but sometimes you 
//               want it in a new tab. This adds a href on some popups.
// @author       "Ben Rabidou" <ben.rabidou@gmail.com>
// @match        https://*.accelo.com/*
// @match        https://*.affinitylive.com/*
// @grant        none
// @updateURL    https://openuserjs.org/meta/brabidou/Accelo_Fix_a_tags_to_be_links_in_addition_to_the_popup..meta.js
// ==/UserScript==

(function() {
    'use strict';
    window.acceloCustomScripts = {};
    window.acceloCustomScripts.runCounter = 0;
    window.acceloCustomScripts.interval = setInterval(function() {
        //We want to kill the timer if its run enough
        if(window.acceloCustomScripts.runCounter >= 15) {
            console.log("Killing acceloCustomScripts");
            clearTimeout(window.acceloCustomScripts.interval);
            return;
        }
        
        //Only run ont the a tags.
        $('a.view_task_button').each(function(obj){
            var element = $(this);
            var new_link = '/?action=view_task&id=' + element.data('task_id');
            element.attr('href', new_link);
        });
        
        //For some reason they wrap the a tag in h1 or h2 but the data and 
        //class name is on the h2 tag not the a tag...Weird.
        $('h1.view_task_button').each(function(obj){
            var element = $(this);
            var element_atag = $(this).find('a');
            var new_link = '/?action=view_task&id=' + element.data('task_id');
            element_atag.attr('href', new_link);
        });  
        $('h2.view_task_button').each(function(obj){
            var element = $(this);
            var element_atag = $(this).find('a');
            var new_link = '/?action=view_task&id=' + element.data('task_id');
            element_atag.attr('href', new_link);
        });   
        
        window.acceloCustomScripts.runCounter ++;
    }, 500);
})();