View Single Post
Old 12-31-2013, 12:32 PM   #34
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Quote:
Originally Posted by l_macd View Post
Can you expand on that?
The bookmarklet is this:
Quote:
javascript: (function(){ a=document.getElementById('mdki_container'); if(a!=null){a.className='show'} else{ url='https://j4n-co.github.com/mass-destroy-kindle-items/mdki/mdki'; mdki_js=document.createElement('SCRIPT'); mdki_js.type='text/javascript'; mdki_js.src=url+'.js'; mdki_css=document.createElement('LINK'); mdki_css.type='text/css'; mdki_css.rel='stylesheet'; mdki_css.media='screen'; mdki_css.href=url+'.css'; document.getElementsByTagName('head')[0].appendChild(mdki_css); document.getElementsByTagName('head')[0].appendChild(mdki_js); }; }) ();
As you can see, the (new) location of the script is: https://j4n-co.github.com/mass-destr...s/mdki/mdki.js with some css at: https://j4n-co.github.com/mass-destr.../mdki/mdki.css. It is a simple matter to look at the code and see it's not doing anything sinister. You can also use the homepage button to view the GitHub project (and fork it, if you wish). It is hosted by a fairly reputable group, and all the code is easily viewed, and if you really want as an added precaution you can host the actual javascript yourself, so no third parties are involved, they can't change it on you (if you control the source) and it's all as safe as can be. Just save the linked js and css files in your choice of home web server, cloud storage, personal website, or whatever, then edit the bookmarklet to show the new source. It is by design simple to do so: simply redefine
Quote:
url='https://j4n-co.github.com/mass-destroy-kindle-items/mdki/mdki'
as the new location, where %url%.js and %url%.css are the linked resources.

It is actually explained on the home page:
Quote:
The Code

The bookmarklet injects the following javascript onto the page. It creates a DOM element with a text input, sets a keyup event on the input, finds the ID's of items that matches the text input, then calls the function amazon uses to delete items, Fion.deleteItem.


Code:
  function mdki(){
  
  var div;
  var input;
  var button;
  var v; 
  var a = document.getElementsByClassName('rowBodyCollapsed');
  var b = document.getElementsByClassName('headerTitle');
  var c = [];
  var count = 0; 

  function make_mdki_dom(){
    div = document.createElement('div');
    div.id='mdki_container';
    h1 = document.createElement('h1');
    h1.innerHTML='Mass Delete Kindle Items';
    hr=document.createElement('hr');
    label=document.createElement('label');
    label.for='mdki_input';
    label.innerHTML='enter the title of the items you wish to delete';
    
    input=document.createElement('input');
    input.type='text';
    input.name='mdki_input';
    input.id='mdki_input';
    input.value='';
    input.addEventListener('keyup', mdki_keyup);
    
    button=document.createElement('button');
    button.id='mdki_button';
    button.innerHTML='delete these items';
    button.addEventListener('click',mdki_click)
      
    close_div=document.createElement('div');
    close_div.id="close_div";
    close_div.innerHTML= '✖';   
    close_div.addEventListener('click', close);
    
    div.appendChild(h1);
    div.appendChild(hr);
    div.appendChild(label);
    div.appendChild(input);
    div.appendChild(button);
    div.appendChild(close_div);
    document.body.appendChild(div);
  } 
  
  function mdki_click(event){
    button=event.target
    v=input.value;
    button.setAttribute('disabled','disabled'); 
    delete_items();
  }
  
  function mdki_keyup(event){
    v=input.value;
    for(var i = 0; i<b.length; i++) {
      b[i].className = b[i].className.replace(/mdki_highlight/g,'');        
      if (b[i].textContent.match(v)){
        b[i].className += " mdki_highlight";  
      }
    }
  }

  function close(event){
    div.className = '';
    input.value = '';
    for(var i = 0; i<b.length; i++) {  
      b[i].className = b[i].className.replace(/mdki_highlight/g,'');        
    }
  }

  make_mdki_dom();
  input.focus();
  div.className = 'show';
  
  function delete_items(){
    if (a.length == b.length){
      for(var i = 0; i<b.length; i++) {
        if (b[i].textContent.match(v)) {
          c.push([i]);
          count +=1;
        }
      };
      
      if (count == 0){
        alert("There are no items with the title '"+v+"' on this page")
        button.removeAttribute('disabled');
        v.value = "";  
      } else {
      
        var conf = confirm(count+" items with the title:'"+v+"' will be deleted");      
        
        if (conf){
          for (i in c){
            Fion.deleteItem('deleteItem_'+a[c[i]].getAttribute('asin'));        
          }
        }
        else {
          c = [];
          count = 0; 
          button.removeAttribute('disabled');
          return false;  
        }
      }
    }
  }
}
mdki();

Last edited by eschwartz; 12-31-2013 at 12:36 PM.
eschwartz is offline   Reply With Quote