Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name HP OUTLET CPU FILTER
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description Create Filters
- // @author xThomas/xTh
- // @include https://h41369.www4.hp.com/pps-offers.php?prod_cat=notebook_pcs
- // @grant none
- // ==/UserScript==
- function createButton(txt, callback_function){
- // This code creates a new <button> element:
- let b = document.createElement("button");
- // This attribute makes the button not cause a page refresh, as the default for a button in form is "submit"
- b.setAttribute("type","button");
- // Make the button toggleable - two-state widget
- b.setAttribute("state","off");
- // Set the callback function
- // b.setAttribute("onclick", callback_function);
- b.onclick = callback_function;
- // To add text to the <button> element, you must create a text node first. This creates a text node:
- let node = document.createTextNode(txt);
- // Then you must append the text node to the <button> element:
- b.appendChild(node);
- // Finally you must append the new element to an existing element.
- // This code finds an existing element:
- let element = document.getElementById("notebook_pcs");
- let child = element.firstElementChild;
- // This code appends the new element to the existing element:
- element.insertBefore(b, child);
- return b;
- }
- function loaded(){
- function getMatchingRows(string){
- // RUN ONCE
- let match = [];
- for (var i = rows.length-1; i >= 1; i--) {
- let innertext = rows[i].children[0].innerHTML;
- if (innertext.search(string) !== -1){
- match.push(rows[i]);
- }
- }
- return match;
- }
- function toggleClassVisibility(string){
- // changes css styling for a class - use to toggle between on/off filters...
- }
- var rows = document.querySelector('#notebook_pcs table tbody').rows;
- createButton("i9", function(){alert("fuck")});
- let notebooks_i9 = getMatchingRows(" i9");
- for (var i = notebooks_i9.length - 1; i >= 0; i--) {
- console.log(notebooks_i9[i].children[0].innerHTML);
- }
- // createButton("i7", "alert(document.getElementById('notebook_pcs'))");
- // createButton("i5", 'alert("Hello World!")');
- // createButton("i3", 'alert("Hello World!")');
- // createButton("r9", 'alert("Hello World!")');
- // createButton("r7", 'alert("Hello World!")');
- // createButton("r5", 'alert("Hello World!")');
- // createButton("r3", 'alert("Hello World!")');
- }
- (function() {
- 'use strict';
- if (document.readyState == "complete" || document.readyState == "loaded" || document.readyState == "interactive") {
- loaded();
- } else {
- document.addEventListener("DOMContentLoaded", function(event) {
- loaded();
- });
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment