Greasy Fork is available in English.

Direct download from Google Play

Adds APKPure, APKMirror, APK-DL and Evozi download buttons to Google Play when browsing apps. This script is based on yurenchen's "google play apk downloader".

Version au 19/03/2018. Voir la dernière version.

// ==UserScript==
// @name         Direct download from Google Play
// @namespace    StephenP
// @version      1.9.0
// @description  Adds APKPure, APKMirror, APK-DL and Evozi download buttons to Google Play when browsing apps. This script is based on yurenchen's "google play apk downloader".
// @author       StephenP
// @match        https://play.google.com/*
// @match        http://play.google.com/*
// @grant        none
// ==/UserScript==
var ui=checkUI();
//alert("ui type: "+ui);
var wlButton;
var pageURL;
(function() {
    'use strict';
    pageURL=location.href;
    if(pageURL.includes("details?id=")){
       addButtons();
    }
    setInterval(checkReload, 3000);
})();
function checkReload(){
    if(pageURL!=location.href){
        //alert(document.getElementById("apkdlbutton"));
        while(document.getElementById("apkdlbutton")!==null){//se ci sono ancora i pulsanti
            setTimeout(function(){},1000);
        }
        if(document.getElementsByClassName("play-logo").length>0){//esistono le vere classi html?
            while(document.getElementsByClassName("buy-button-container")===null){
                setTimeout(function(){},1000);
            }
        }
        else{
        }
        //alert(pageURL+" vs. "+location.href);
        if(location.href.includes("details?id=")){
            addButtons();
        }
        pageURL=location.href;
        wlButton=null;
    }
}
function addButtons(){
    var price=-1;
    var installButton=null;
    var instWishButtons=[];
    if(ui<=2){
        installButton=document.getElementsByClassName("buy")[0];
        price=installButton.firstElementChild.firstElementChild.getElementsByTagName("META")[1].content;
    }
    else{
        instWishButtons=getUglyUIButtons();
        installButton=instWishButtons[1];
        do{
            installButton=installButton.parentNode;
            //alert(installButton.tagName);
        }while(installButton.tagName!="C-WIZ");
        price=installButton.firstElementChild.firstElementChild.getElementsByTagName("META")[1].content;
    }
        if(price==0){
            var html;
            var buttonslist;
            var id=location.search.match(/id=(.*)/)[1].split("&", 1);
            var apkpureURL='https://m.apkpure.com/genericApp/'+id+'/download';
            var evoziURL='https://apps.evozi.com/apk-downloader/?id='+id;
            var apkdlURL='http://apkfind.com/store/captcha?app='+id;
            var apkmirrorURL='https://www.apkmirror.com/?post_type=app_release&searchtype=apk&s='+id;
            wlButton = document.createDocumentFragment();
            var wishListButton;
            //alert(instWishButtons.length);
            if(ui<=2){
                wishListButton=document.getElementsByClassName("id-wishlist-display")[0];
            }
            else{
                wishListButton=instWishButtons[0];
                do{
                    wishListButton=wishListButton.parentNode;
                    //alert(wishListButton.tagName);
                }while(wishListButton.tagName!="C-WIZ");
            }
            //alert(wishListButton.innerHTML);
            wlButton.appendChild(wishListButton);
            if(ui==1){ //menubutton==0 means there is no sliding menu, an element only occurring in mobile view.
                buttonslist = document.getElementsByClassName("details-actions")[0];
                html='<span id="apkpurebutton"><a style="background-color: #24cd77" class="medium play-button download-apk-button apps ">APKPure</a></span><span id="apkdlbutton"><a href="'+apkdlURL+'" style="background-color: #009688" class="medium play-button download-apk-button apps ">APK-DL</a></span><span><a href="'+evoziURL+'" style="background-color: #286090" class="medium play-button download-apk-button apps ">Evozi</a></span><span><a href="'+apkmirrorURL+'" style="background-color: #FF8B14" class="medium play-button download-apk-button apps ">APKMirror</a></span>';
            }
            else if(ui==2){
                buttonslist = document.getElementsByClassName("details-actions-right")[0];
                html='<span id="apkpurebutton"><p style="background-color: #24cd77" class="large play-button download-apk-button apps ">APKPure</p></span><span id="apkdlbutton"><a href="'+apkdlURL+'" style="background-color: #009688" class="large play-button download-apk-button apps ">APK-DL</a></span><span><a href="'+evoziURL+'" style="background-color: #286090" class="large play-button download-apk-button apps ">Evozi</a></span><span><a href="'+apkmirrorURL+'" style="background-color: #FF8B14" class="large play-button download-apk-button apps ">APKMirror</a></span>';
            }
            else{
                buttonslist = installButton.parentNode;
                html='<span id="apkpurebutton"><a style="background-color: #24cd77" class="medium play-button download-apk-button apps ">APKPure</a></span><span id="apkdlbutton"><a href="'+apkdlURL+'" style="background-color: #009688" class="medium play-button download-apk-button apps ">APK-DL</a></span><span><a href="'+evoziURL+'" style="background-color: #286090" class="medium play-button download-apk-button apps ">Evozi</a></span><span><a href="'+apkmirrorURL+'" style="background-color: #FF8B14" class="medium play-button download-apk-button apps ">APKMirror</a></span>';
            }
            buttonslist.innerHTML=buttonslist.innerHTML+html;
            buttonslist.appendChild(wlButton);
            var apkpureButton=document.getElementById("apkpurebutton");
            apkpureButton.onclick=function(){pureDDL(apkpureURL);};
        }
}
function pureDDL(apkpureURL){
    try{
        document.body.removeChild(document.getElementById('apkpureFrame'));
    }
    catch(err){
    }
    finally{
        var hiddenFrame=document.createElement("iframe");
        hiddenFrame.style.width="0";
        hiddenFrame.style.height="0";
        hiddenFrame.setAttribute('id', 'apkpureFrame');
        hiddenFrame.setAttribute('src', apkpureURL);
        hiddenFrame.setAttribute('frameborder', "0");
        document.body.appendChild(hiddenFrame);
    }
}
function getUglyUIButtons()
{
  var matchingElements=[];
  var allElements = document.getElementsByTagName('button');
  for (var i = 0, n = allElements.length; i < n; i++)
  {
    if (allElements[i].getAttribute("data-item-id")!==null)
    {
      if (allElements[i].getAttribute("data-item-id").startsWith("%.@.")===true){
          matchingElements.push(allElements[i]);
      }
    }
  }
  return matchingElements;
}
function checkUI(){
    //Different UIs:
    //1=Mobile HTML
    //2=Desktop HTML
    //3=Mobile UglyUI
    //4=Desktop UglyUI
    var check;
    try{
        if(document.getElementsByClassName("action-bar-menu-button").length>0){
            check=1;
        }
        else{
            if(document.getElementsByClassName("play-logo").length>0){
                check=2;
            }
            else{
                check=4;
                var metaTags=document.head.getElementsByTagName("meta");
                for(var i=0;i<metaTags.length;i++){
                    if(metaTags[i].getAttribute("name")=="mobile-web-app-capable"){
                        check=3;
                    }
               }
            }
        }
    }
    catch(err){
        alert(err);
    }
    return check;
}