WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Extentions Repository Browser Userscript  (Read 187 times)

Offline teh-botol

  • WikiUser
  • *
  • Posts: 18
Extentions Repository Browser Userscript
« on: January 16, 2017, 06:05:19 AM »
Hi Guys,

I just want to share a script to browse extensions repository without a hassle.

Background:
I use TinyCoreLinux to make an appliance.
Mostly working with emulator and or ssh + X11 forwarding.
The annoying part is browsing the extension's description, list and dependencies.

Tested with Chrome and extension Tampermonkey (http://tampermonkey.net/).
Basically, the Tampermonkey will run the script at specific url with jQuery injected.
But the script itself can be used to any modern browser with other userscript manager.


Here goes:
Code: [Select]
// ==UserScript==
// @name         TinyCore Repository
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Less hassle browsing extentions.
// @author       adit.bisa@gmail.com
// @match        http://tinycorelinux.net/*/tcz/
// @grant        none
// @require      https://code.jquery.com/jquery-2.1.4.min.js
// ==/UserScript==

(function() {
    'use strict';

    var list = $('body').text().split('\n');
    $('body').html(
        '<style>' +
        ' body, input { font: 12px courier; } ' +
        ' a:hover { text-decoration: underline; } ' +
        ' .tcz > a { display: none; text-decoration: none; }' +
        ' .tcz:hover > a { display: inline-block; }' +
        ' #preview { position: fixed; top: 10px; right: 10px; }' +
        ' #url { width: 700px; }' +
        ' #browse { width: 678px; border: 1px solid #aaa; padding: 10px; height: 500px; overflow: auto; white-space: pre; }' +
        ' .error { color: red; }' +
        '</style>' +
        '<div id="preview">' +
        '  <input id="url" type="text">' +
        '  <br>' +
        '  <div id="browse">&nbsp;</div>' +
        '</div>'
    );
   
    for (var i=0; i<list.length; i++) {
        var fname = list[i];
        var tcz = $('<div class="tcz">').appendTo('body');
        tcz.data('fname', fname);
        tcz.append('<span class="fname">' + fname + '</span>');
        tcz.append(' <a href="#' + fname + '.info" class="info">[info]</a>');
        tcz.append(' <a href="#' + fname + '.list" class="list">[list]</a>');
        tcz.append(' <a href="#' + fname + '.dep" class="dep">[dep]</a>');
    }
   
    $('a').click(function(event){
        event.preventDefault();
        var a = $(this);
        var url = document.location + a.attr('href').substr(1);
        $.ajax({
            url: url,
            success: function(data){
                $('#url').val(url);
                $('#browse').html(data);
            },
            error: function(){
                $('#url').val(url);
                $('#browse').html('<span class="error">Error!</span>');
            }
        });
        return false;
    });
})();


BR,
adit

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1344
Re: Extentions Repository Browser Userscript
« Reply #1 on: January 16, 2017, 07:11:02 AM »
Hi teh-botol,
pretty cool!
works with Greasemonkey in Firefox, too.
Thanks.
Download a copy and keep it handy: Core book ;)