sajad / -shaqayeq pdf downloader

// ==UserScript==
// @name         -shaqayeq pdf downloader
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       Sajad
// @match        http://online.sanapezeshki.com/unit/*
// @grant        none
// @run-at       document-idle
// @license      MIT
// ==/UserScript==

function findButtonbyTextContent(text) {
  var buttons = document.querySelectorAll('button');
  for (var i=0, l=buttons.length; i<l; i++) {
    if (buttons[i].firstChild.nodeValue == text)
      return buttons[i];
  }
}

(function() {
    'use strict';

    var B1 = findButtonbyTextContent('View Fullscreen');
    B1.innerHTML = "Download PDF";
    var pdf_url = B1.parentNode.href.replace("http://online.sanapezeshki.com/wp-content/plugins/pdf-poster/pdfjs/web/viewer.php?file=","") ;

    B1.parentNode.href = pdf_url.replace("&download=false&print=false&openfile=false","");
    B1.parentNode.setAttribute("download", "file.pdf");
})();