Steam Wishlist Scraper

Scrapes steam wishlist into a CSV file for Excel / LibreOffice

اعتبارا من 16-03-2018. شاهد أحدث إصدار.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @name         Steam Wishlist Scraper
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Scrapes steam wishlist into a CSV file for Excel / LibreOffice
// @author       [email protected]
// @match        http://store.steampowered.com/wishlist/profiles/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Scrape titles and release dates
    var titles = document.getElementsByClassName('title');
    var dates = document.getElementsByClassName('value release_date');
    var output = [];
    var clean_output = [];
    for(var k in titles){
        var temp_title = titles[k].innerText;
        var temp_date = dates[k].innerText;
        if (typeof temp_title != 'undefined' && temp_title.length != 0 && typeof temp_date != 'undefined' && temp_date.length != 0){
            // Strip commas, add "^" for newlines
            temp_title = "^" + temp_title.replace(/,/g,"");
            temp_date = temp_date.replace(/,/g,"");
            output.push(temp_title.trim());
            output.push(temp_date.trim());
        }
    }
    output[0] = output[0].slice(1, output[0].length);
    clean_output = cleanArray(output);
    console.log(output);

    // Add CSV download button when we finish compiling the list
    window.addEventListener('load', () => {
    addButton('Download CSV', downloadCSV);
    });

    // Removes "undefined" and null entries in the array, trims whitespace
    function cleanArray(arr) {
        var len = arr.length, i;

        for(i = 0; i < len; i++ ) {
            if (arr[i]) {
                arr.push(arr[i]);  // copy non-empty values to the end of the array
            }
        }

        arr.splice(0 , len);  // cut the array and leave only the non-empty values

        return arr;
    }

    // Add a button
    function addButton(text, onclick, cssObj) {
        cssObj = cssObj || {position: 'absolute', top: '7%', left:'4%', 'z-index': 3};
        let button = document.createElement('button'), btnStyle = button.style;
        document.body.appendChild(button);
        button.innerHTML = text;
        button.onclick = onclick;
        Object.keys(cssObj).forEach(key => btnStyle[key] = cssObj[key]);
        return button;
    }

    // Generate CSV file and download
    function downloadCSV(args) {
        var data, filename, link;
        //var csv = output.toString();
        var csv = clean_output.toString();
        if (csv == null) return;

        console.log(csv);

        // Replaces "|" with newlines
        csv = csv.replace( /\^/g, "\n");
        csv = csv.replace(/,,/g, ',')

        console.log(csv);

        filename = 'wishlist.csv';

        if (!csv.match(/^data:text\/csv/i)) {
            csv = 'data:text/csv;charset=utf-8,' + csv;
        }
        data = encodeURI(csv);

        link = document.createElement('a');
        link.setAttribute('href', data);
        link.setAttribute('download', filename);
        link.click();
    }

})();