zitot

outletHP-filter

Jan 15th, 2020
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         HP OUTLET CPU FILTER
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  Create Filters
  6. // @author       xThomas/xTh
  7. // @include      https://h41369.www4.hp.com/pps-offers.php?prod_cat=notebook_pcs
  8. // @grant        none
  9. // ==/UserScript==
  10. function createButton(txt, callback_function){
  11.     // This code creates a new <button> element:
  12.     let b = document.createElement("button");
  13.  
  14.     // This attribute makes the button not cause a page refresh, as the default for a button in form is "submit"
  15.     b.setAttribute("type","button");
  16.  
  17.     // Make the button toggleable - two-state widget
  18.     b.setAttribute("state","off");
  19.    
  20.     // Set the callback function
  21.     // b.setAttribute("onclick", callback_function);
  22.     b.onclick = callback_function;
  23.  
  24.     // To add text to the <button> element, you must create a text node first. This creates a text node:
  25.     let node = document.createTextNode(txt);
  26.    
  27.     // Then you must append the text node to the <button> element:
  28.     b.appendChild(node);
  29.  
  30.     // Finally you must append the new element to an existing element.
  31.     // This code finds an existing element:
  32.     let element = document.getElementById("notebook_pcs");
  33.     let child = element.firstElementChild;
  34.  
  35.     // This code appends the new element to the existing element:
  36.     element.insertBefore(b, child);
  37.  
  38.     return b;
  39. }
  40.  
  41.  
  42.  
  43. function loaded(){
  44.     function getMatchingRows(string){
  45.         // RUN ONCE
  46.         let match = [];
  47.         for (var i = rows.length-1; i >= 1; i--) {
  48.             let innertext = rows[i].children[0].innerHTML;
  49.             if (innertext.search(string) !== -1){
  50.                 match.push(rows[i]);
  51.             }
  52.         }
  53.         return match;
  54.     }
  55.  
  56.     function toggleClassVisibility(string){
  57.         // changes css styling for a class - use to toggle between on/off filters...
  58.  
  59.     }
  60.  
  61.  
  62.     var rows = document.querySelector('#notebook_pcs table tbody').rows;
  63.     createButton("i9", function(){alert("fuck")});
  64.  
  65.     let notebooks_i9 = getMatchingRows(" i9");
  66.     for (var i = notebooks_i9.length - 1; i >= 0; i--) {
  67.         console.log(notebooks_i9[i].children[0].innerHTML);
  68.     }
  69.  
  70.     // createButton("i7", "alert(document.getElementById('notebook_pcs'))");
  71.     // createButton("i5", 'alert("Hello World!")');
  72.     // createButton("i3", 'alert("Hello World!")');
  73.     // createButton("r9", 'alert("Hello World!")');
  74.     // createButton("r7", 'alert("Hello World!")');
  75.     // createButton("r5", 'alert("Hello World!")');
  76.     // createButton("r3", 'alert("Hello World!")');
  77. }
  78.  
  79. (function() {
  80.     'use strict';
  81.  
  82.     if (document.readyState == "complete" || document.readyState == "loaded" || document.readyState == "interactive") {
  83.         loaded();
  84.     } else {
  85.         document.addEventListener("DOMContentLoaded", function(event) {
  86.             loaded();
  87.         });
  88.     }
  89. })();
Advertisement
Add Comment
Please, Sign In to add comment