summaryrefslogtreecommitdiffstats
path: root/HTML/script.js
blob: 90e8da7da7a968c8ce318df7ac485fedb62269b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
 * @copyright Copyright (c) 2011-2012 Romain d'Alverny
 * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3 and later
 *
 * Redirect browser to URL with GET parameters:
 * - l = html[lang]
 * - p = meta[product:id]
 *
*/

function StartPage(url) {
    this.location = url;
}

StartPage.prototype.run = function () {
    var product_id = '',
        lang       = '',
        args       = [];

    document.getElementsByTagName("body").item(0).setAttribute("class", "");

    if (null !== (product_id = this.getProductId())) {
        args.push('p=' + product_id);
    }

    if (null !== (lang = this.getLocale())) {
        args.push('l=' + lang);
    }

    if (args.length > 0) {
        this.location = [this.location, args.join('&')].join('?');
    }
    parent.location = this.location;

    return true;
};

StartPage.prototype.getLocale = function () {
    var ret = null;

    try {
        ret = parent.window.document.documentElement.attributes.getNamedItem('lang').value.trim();
    } catch (e) {}

    return ret;
};

StartPage.prototype.getProductId = function () {
    var ret = null,
        t = document.getElementsByTagName('meta');

    for (var i = 0; i < t.length; i += 1) {
        if (t.item(i).getAttribute('name') === 'product:id') {
            ret = t.item(i).getAttribute('content').trim();
            break;
        }
    }

    return ret;
};