QTI document downloader

QTI createpoint.qti.qualcomm.com document download to file "DocNumber_version_title" old style small letter file name.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @license MIT
// @name         QTI document downloader
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  QTI createpoint.qti.qualcomm.com document download to file "DocNumber_version_title" old style small letter file name.
// @author       hk3f
// @match        https://createpoint.qti.qualcomm.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=qualcomm.com
// @grant    GM_xmlhttpRequest
// @grant    GM_openInTab
// @grant    GM_registerMenuCommand
// @grant    GM_unregisterMenuCommand
// @run-at   context-menu
// ==/UserScript==

(function() {
    'use strict';
  //load context-menu URL
  let el = document.activeElement;
  if (el.tagName !== "A") el = el.closest("a");
  if (el) {
  let url = el.href;
  console.log(url);
  //parse URL title ID
  let idx = url.slice(url.lastIndexOf("/")+1 , url.length);
  console.log('TitleID=' , idx);
  //get title info json data
  let infoUrl = "https://createpoint.qti.qualcomm.com/chipcenter/title/" + idx;
  console.log('Url Of Title detailed info = ' , infoUrl);
  GM_xmlhttpRequest({
    method: 'GET',
    url: infoUrl,
    headers: {
        'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
        'Accept': 'application/atom+xml,application/xml,text/xml',
    },
    onload: function(response) {
        var obj = JSON.parse(response.responseText);
        console.log("Target Document ID = ", obj.documents[0].id);
        //download target document with old style file name
        let urlTarget = "https://createpoint.qti.qualcomm.com/chipcenter/download/title/" + obj.documents[0].id;
        console.log("Target Document URL = ", urlTarget);
        GM_openInTab(urlTarget);
    }

  });

} else console.log('not actually a link');


})();