Last active
September 30, 2020 00:12
-
-
Save debbbbie/59bf0a070b7daafa7c42a819292bf2fd to your computer and use it in GitHub Desktop.
Focus Mate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Focussi CBA Mate | |
// @namespace https://www.focussi.com | |
// @version 1.0.6 | |
// @author Donnie Ian | |
// @hostAt https://gist.github.com/debbbbie/59bf0a070b7daafa7c42a819292bf2fd | |
// @updateURL https://gist.githubusercontent.com/debbbbie/59bf0a070b7daafa7c42a819292bf2fd/raw/focus_mate.user.js | |
// @downloadURL https://gist.githubusercontent.com/debbbbie/59bf0a070b7daafa7c42a819292bf2fd/raw/focus_mate.user.js | |
// @match https://*.focussi.com/* | |
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js | |
// @require https://raw.githubusercontent.com/websanova/js-url/master/src/url.js | |
// @grant unsafeWindow | |
// @grant GM_addStyle | |
// ==/UserScript== | |
async function asyncForEach(array, callback) { | |
for (let index = 0; index < array.length; index++) { | |
await callback(array[index], index, array); | |
} | |
} | |
// eslint-disable-next-line no-undef | |
jQuery.noConflict(); var $ = jQuery; | |
// example page: https://connect.focussi.com/default.aspx?r=87&ot=13&o=14285 | |
var inject_sp_detail = async function ($a) { | |
var data = await $.get($a.attr('href')); | |
var sp = $.trim($(data).find("th:contains(Focus Service Plan) ~ td").text()); | |
var sp_url = `https://smartstart.focussi.com/browse/service_plan/${sp}`; | |
$a.after(`<span class='tm-service-plan-token'>SP: <a target='_blank' href='${sp_url}'>${sp}</a></span>`); | |
}; | |
// example page: https://connect.focussi.com/default.aspx?r=115&ot=11&o=701397# | |
var inject_policy_detail = async function (coverage_tr) { | |
var coverage_tr = $(coverage_tr); | |
var data = await $.get($coverage_tr.find("td a").attr("href")); | |
$coverage_tr.find("td.tm-policy").html( | |
$(data).find("#productpanel .streamframe table.grid tr a.stream-component").map((stream_link) => { | |
return `<a target='_blank' href='${stream_link.href}' class='tm-policy-link'>${stream_link.innerText}</a>`; | |
}).join("<br/>") | |
); | |
await inject_sp_detail($coverage_tr.find("a.tm-policy-link")); | |
}; | |
var fetch_policy_detail = async function (coverage_tr) { | |
var $coverage_tr = $(coverage_tr); | |
var $a = $coverage_tr.find("td a.stream-component"); | |
var data = await $.get($a.attr("href")); | |
var sp = $.trim($(data).find("th:contains(Focus Service Plan) ~ td").text()); | |
var sp_url = `https://smartstart.focussi.com/browse/service_plan/${sp}`; | |
$a.after(`<span class='tm-service-plan-token'>SP: <a target='_blank' href='${sp_url}'>${sp}</a></span>`); | |
}; | |
$(function () { | |
async function init(){ | |
if (url('?ot') === '9') { | |
var $coverage_table = $("table[id=list]").filter(function () { | |
return $.trim($(this).find("thead tr th:first").text()) === 'Coverage'; | |
}); | |
// add column policy | |
$coverage_table.find("thead tr").find("th:first").after("<th>Policy / Fee</th>"); | |
$coverage_table.find("tbody tr").find("td:first").after("<td class='tm-policy'></td>"); | |
await asyncForEach($coverage_table.find("tbody tr"), inject_policy_detail); | |
} else if (url('?ot') === '14') { // product page | |
// 1. load policy sp info | |
var $policy_table = $("table.grid").filter(function () { | |
return $.trim($(this).find("tbody tr td:first").text()).indexOf('Policy') >= 0; | |
}); | |
await asyncForEach($policy_table.find("tbody tr"), fetch_policy_detail); | |
} | |
}; | |
init(); | |
}); | |
GM_addStyle(` | |
span.tm-service-plan-token { font-size:10px;float:right; padding-right: 5px; } | |
`); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment