NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name VIMENTO- Virtual Mentor
// @namespace kalpdev
// @version 0.4
// @description Provides a summary of PTG from Amazon Webpage
// @author shjaisw
// @match https://www.amazon.co.uk/dp/*
// @match https://www.amazon.com/dp/*
// @match https://www.amazon.in/dp/*
// @match https://www.amazon.ca/dp/*
// @match https://www.amazon.ae/dp/*
// @updateURL https://openuserjs.org/meta/kalpdev.1/Battery_Word_Counter.meta.js
// @require https://code.jquery.com/jquery-3.3.1.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/jquery.mark.es6.min.js
// @require https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js
// @license MIT
// ==/UserScript==
$(window).bind("load", function() {
'use strict';
var zNode = document.createElement('div');
zNode.style.backgroundColor = ' #cfa2e6';
zNode.style.textAlign = 'center';
zNode.innerHTML = '<h2> </h2>';
zNode.setAttribute('id', 'hazwordsContainers');
var tableNode = document.createElement('table');
tableNode.setAttribute('id', 'hazwordsContainerTables');
tableNode.setAttribute('border', 1);
zNode.appendChild(tableNode);
$('#wayfinding-breadcrumbs_container').append(zNode);
$('#hazwordsContainer h2').click(function() {
$('#hazwordsContainerTable_wrapper').toggle('slow');
});
let table_content = generate_table_content();
buildHtmlTable(table_content, $('#hazwordsContainerTables'));
$('#hazwordsContainerTables').DataTable({
"aaSorting": [[3,'desc']]
});
$("head").append (
'<link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet" type="text/css">'
);
});
function buildHtmlTable(myList, elementToAppend) {
var columns = addAllColumnHeaders(myList, elementToAppend);
var tbodyElement = $('<tbody/>');
for (var i = 0 ; i < myList.length ; i++) {
var row$ = $('<tr/>');
for (var colIndex = 0 ; colIndex < columns.length ; colIndex++) {
var cellValue = myList[i][columns[colIndex]];
if (cellValue == null) { cellValue = ""; }
row$.append($('<td/>').html(cellValue));
}
tbodyElement.append(row$);
}
elementToAppend.append(tbodyElement);
}
function addAllColumnHeaders(myList, elementToAppend)
{
var columnSet = [];
var thElement = $('<thead/>');
var headerTr$ = $('<tr/>');
console.log(myList);
for (var i = 0 ; i < myList.length ; i++) {
var rowHash = myList[i];
for (var key in rowHash) {
if ($.inArray(key, columnSet) == -1){
columnSet.push(key);
headerTr$.append($('<th/>').html(key));
}
}
}
thElement.append(headerTr$);
elementToAppend.append(thElement);
return columnSet;
}
function generate_table_content() {
let marked_hazardous_words = mark_hazardous_words_on_page();
let hazardous_words_config = get_hazardous_words_config();
let data_to_load = [];
var hazardous_words_map = hazardous_words_config.reduce(function(map, obj) {
map[obj.Keyword.toLowerCase()] = { Reference: obj.Reference, priority : obj.priority };
return map;
}, {});
$.each(marked_hazardous_words, function(key, value) {
let data_node = {};
data_node.Keyword = key;
data_node.Reference = hazardous_words_map[data_node.Keyword].Reference;
data_to_load.push(data_node);
});
return data_to_load;
}
function mark_hazardous_words_on_page() {
let just_hazardous_words_from_config = get_just_hazardous_words_from_config();
let hazardous_words_on_page = {};
console.log(Date.now());
$('#dp').mark(just_hazardous_words_from_config, {
filter: function(text_node, keyword, total_counter, counter) {
let lower_case_keyword = keyword.toLowerCase();
hazardous_words_on_page[lower_case_keyword] = parseInt(counter + 1);
return true;
},
accuracy: {
"value": "exactly",
"limiters": [",", ":", "."]
},
separateWordSearch: false
});
console.log(Date.now());
return hazardous_words_on_page
}
function get_just_hazardous_words_from_config() {
let hazardous_words_from_config = get_hazardous_words_config();
let hazardous_words = [];
$.each(hazardous_words_from_config, function(k, v) {
hazardous_words.push(v.Keyword);
});
return hazardous_words;
}
function get_hazardous_words_config() {
return [
{
"Keyword": "Builtin",
"Reference": "Available",
"priority": 13
},
{
"Keyword": "in the box",
"Reference": "Available",
"priority": 14
},
{
"Keyword": "Package Content",
"Reference": "Available",
"priority": 111
},
{
"Keyword": "Package Includes",
"Reference": "Available",
"priority": 112
},
{
"Keyword": "in a box",
"Reference": "Available",
"priority": 111
},
];
}