Pith - otc_applet
otc_applet/otc@vgmlr/applet.js [10.2 kb]
Modified: 21:12:46 56 026 (14 May 026)
16 Days Ago
// otc applet
// vgmlr.com/mlwrk
// 55.026.1

const Applet = imports.ui.applet;
const GLib = imports.gi.GLib;
const Lang = imports.lang;
const Mainloop = imports.mainloop;
const PopupMenu = imports.ui.popupMenu;
const Util = imports.misc.util;
const St = imports.gi.St;
const Clutter = imports.gi.Clutter;

function OTCApplet(orientation, panel_height, instance_id) {
    this._init(orientation, panel_height, instance_id);
}

OTCApplet.prototype = {
    __proto__: Applet.TextApplet.prototype,

    _init: function(orientation, panel_height, instance_id) {
        Applet.TextApplet.prototype._init.call(this, orientation, panel_height, instance_id);
        this.set_applet_label(_("000 000"));

        this.menuManager = new PopupMenu.PopupMenuManager(this);
        this.menu = new Applet.AppletPopupMenu(this, orientation);
        this.menuManager.addMenu(this.menu);
        this._contentSection = new PopupMenu.PopupMenuSection();
        this.menu.addMenuItem(this._contentSection);

        this.refresh();
        // loop every 60 seconds
        this.timeout = Mainloop.timeout_add_seconds(60, Lang.bind(this, this.refresh));
        this.keepUpdating = true;
    },

    refresh: function() {
        var gdate = new Date();
        var ndate = new Date(gdate.getFullYear(), 2, 20);
        var clday = 1000 * 60 * 60 * 24;
        var wktot = (365.25 / 5).toFixed(0);
        if (gdate >= ndate) { // past new year
            var yrotc = gdate.getFullYear() - 2000;
            var dyotc = Math.ceil((gdate - ndate) / clday);
            var dfotc = (365.25 - dyotc).toFixed(0);
            var wkotc = Math.ceil(dyotc / 5);
        } else { // before new year
        var yrotc = gdate.getFullYear() - 2001;
        var dfotc = Math.ceil((ndate - gdate) / clday);
        var dyotc = (365.25 - dfotc).toFixed(0);
        var wkotc = Math.ceil(dyotc / 5);
        }
        var wklef = wktot - wkotc;
        var dyper = ((dyotc / 365.25) * 100).toFixed(1);
        var wkper = (100 - dyper).toFixed(1);

        this.set_applet_label(_(dyotc + " 0" + yrotc));
        this.set_applet_tooltip(_("Day " + dyotc + " Week " + wkotc + " Year 0" + yrotc));

        this.menu.removeAll();

        var threeAndTwo = "       ";
        var twoAndTwo = "         ";
        var twoAndOne = "           ";
        var oneAndOne = "              ";
        var dSpace = "";
        if (dyotc > 99 && dyper > 9) {
            dSpace = threeAndTwo;
        } else if (dyotc > 9 && dyper > 9) {
            dSpace = twoAndTwo;
        } else if (dyotc > 9 && dyper < 10) {
            dSpace = twoAndOne;
        } else if (dyotc < 10 && dyper < 10) {
            dSpace = oneAndOne;
        }

        // otc day
        let dayItem = new PopupMenu.PopupBaseMenuItem({ reactive: true });
        let dayLabel = new St.Label({ text: "Day", style: "color: black; width: 60px; text-align: left;" });
        // let dayCount = new St.Label({ text: String(dyotc || 0), style: "color: black; width: 90px; text-align: left;" });
        let dayCount = new St.Label({ style: "width: 90px; text-align: left;" });
        dayCount.get_clutter_text().set_markup("<span color='black'>" + String(dyotc || 0) + "</span> " + String(dSpace) + " <span color='gray'>" + String(dyper || 0) + "%</span>");
        let dayValues = new St.Label({ text: String(dfotc || 0), style: "color: gray; width: 40px; text-align: right;" });
        dayItem.addActor(dayLabel);
        dayItem.addActor(dayCount);
        dayItem.addActor(dayValues);
        dayItem.actor.show_all();
        this.menu.addMenuItem(dayItem);

        // otc week
        let weekItem = new PopupMenu.PopupBaseMenuItem({ reactive: true });
        let weekLabel = new St.Label({ text: "Week", style: "color: black; width: 60px; text-align: left;" });
        let weekCount = new St.Label({ text: String(wkotc || 0), style: "color: black; width: 90px; text-align: left;" });
        let weekValues = new St.Label({ text: String(wklef || 0), style: "color: gray; width: 40px; text-align: right;" });
        weekItem.addActor(weekLabel);
        weekItem.addActor(weekCount);
        weekItem.addActor(weekValues);
        weekItem.actor.show_all();
        this.menu.addMenuItem(weekItem);

        // otc year
        let yearItem = new PopupMenu.PopupBaseMenuItem({ reactive: true });
        let yearLabel = new St.Label({ text: "Year", style: "color: black; width: 60px; text-align: left;" });
        let yearCount = new St.Label({ text: "4,547,742,0" + String(yrotc || 0), style: "color: black; width: 90px; text-align: left;" });
        let yearValues = new St.Label({ text: "(0" + String(yrotc || 0) + ")", style: "color: gray; width: 40px; text-align: right;" });
        yearItem.addActor(yearLabel);
        yearItem.addActor(yearCount);
        yearItem.addActor(yearValues);
        yearItem.actor.show_all();
        this.menu.addMenuItem(yearItem);

        // hr
        this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());

        // seasons
        var seasonNow = new Date();
        var seasonYear = seasonNow.getFullYear();
        var seasonMs = 86400000;

        var startSpring = new Date(seasonYear, 2, 20); 
        var endSpring = new Date(seasonYear, 5, 20);
        var startSummer = new Date(seasonYear, 5, 20); 
        var endSummer = new Date(seasonYear, 8, 21);
        var startFall = new Date(seasonYear, 8, 21); 
        var endFall = new Date(seasonYear, 11, 21);
        var startWinter = new Date(seasonYear, 11, 21); 
        var endWinter = new Date(seasonYear, 2, 20);

        // spring
        var inSpring = (seasonNow >= startSpring && seasonNow <= endSpring);
        // days since
        var springStart = inSpring ? Math.floor((seasonNow - startSpring) / seasonMs) : " -";
        // days next
        var nextSpring = (seasonNow > startSpring) ? new Date(seasonYear + 1, 2, 20) : startSpring;
        var springWhen = inSpring ? " -" : Math.ceil((nextSpring - seasonNow) / seasonMs);

        // summer
        var inSummer = (seasonNow >= startSummer && seasonNow <= endSummer);
        var summerStart = inSummer ? Math.floor((seasonNow - startSummer) / seasonMs) : " -";
        var nextSummer = (seasonNow > startSummer) ? new Date(seasonYear + 1, 5, 20) : startSummer;
        var summerWhen = inSummer ? " -" : Math.ceil((nextSummer - seasonNow) / seasonMs);

        // fall
        var inFall = (seasonNow >= startFall && seasonNow <= endFall);
        var fallStart = inFall ? Math.floor((seasonNow - startFall) / seasonMs) : " -";
        var nextFall = (seasonNow > startFall) ? new Date(seasonYear + 1, 8, 21) : startFall;
        var fallWhen = inFall ? " -" : Math.ceil((nextFall - seasonNow) / seasonMs);

        // winter
        var inWinter = (seasonNow >= startWinter && seasonNow <= endWinter);
        var winterStart = inWinter ? Math.floor((seasonNow - startWinter) / seasonMs) : " -";
        var nextWinter = (seasonNow > startWinter) ? new Date(seasonYear + 1, 11, 21) : startWinter;
        var winterWhen = inWinter ? " -" : Math.ceil((nextWinter - seasonNow) / seasonMs);

        // spring (days since, days until next)
        let springItem = new PopupMenu.PopupBaseMenuItem({ reactive: true });
        let springLabel = new St.Label({ text: "Spring", style: "color: black; width: 60px; text-align: left;" });
        let springIn = new St.Label({ text: String(springStart || 0), style: "color: black; width: 90px; text-align: left;" });
        let springUntil = new St.Label({ text: String(springWhen || 0), style: "color: gray; width: 40px; text-align: right;" });
        springItem.addActor(springLabel);
        springItem.addActor(springIn);
        springItem.addActor(springUntil);
        springItem.actor.show_all();
        this.menu.addMenuItem(springItem);

        // summer
        let summerItem = new PopupMenu.PopupBaseMenuItem({ reactive: true });
        let summerLabel = new St.Label({ text: "Summer", style: "color: black; width: 60px; text-align: left;" });
        let summerIn = new St.Label({ text: String(summerStart || 0), style: "color: black; width: 90px; text-align: left;" });
        let summerUntil = new St.Label({ text: String(summerWhen || 0), style: "color: gray; width: 40px; text-align: right;" });
        summerItem.addActor(summerLabel);
        summerItem.addActor(summerIn);
        summerItem.addActor(summerUntil);
        summerItem.actor.show_all();
        this.menu.addMenuItem(summerItem);

        // fall
        let fallItem = new PopupMenu.PopupBaseMenuItem({ reactive: true });
        let fallLabel = new St.Label({ text: "Fall", style: "color: black; width: 60px; text-align: left;" });
        let fallIn = new St.Label({ text: String(fallStart || 0), style: "color: black; width: 90px; text-align: left;" });
        let fallUntil = new St.Label({ text: String(fallWhen || 0), style: "color: gray; width: 40px; text-align: right;" });
        fallItem.addActor(fallLabel);
        fallItem.addActor(fallIn);
        fallItem.addActor(fallUntil);
        fallItem.actor.show_all();
        this.menu.addMenuItem(fallItem);

        // winter
        let winterItem = new PopupMenu.PopupBaseMenuItem({ reactive: true });
        let winterLabel = new St.Label({ text: "Winter", style: "color: black; width: 60px; text-align: left;" });
        let winterIn = new St.Label({ text: String(winterStart || 0), style: "color: black; width: 90px; text-align: left;" });
        let winterUntil = new St.Label({ text: String(winterWhen || 0), style: "color: gray; width: 40px; text-align: right;" });
        winterItem.addActor(winterLabel);
        winterItem.addActor(winterIn);
        winterItem.addActor(winterUntil);
        winterItem.actor.show_all();
        this.menu.addMenuItem(winterItem);

        return this.keepUpdating;
    },

    on_applet_clicked: function () {
        this.menu.toggle();
    },

    on_applet_removed_from_panel: function() {
    this.keepUpdating = false;
    if (this.timeout) Mainloop.source_remove(this.timeout);
    this.timeout = 0;
  } 
};

function main(metadata, orientation, panel_height, instance_id) {
    return new OTCApplet(orientation, panel_height, instance_id);
}
Updates
Shim - Android 70.026.1
Wedge - Linux 68.026.1
Wedge - Android 68.026.1
Taper - Linux 64.026.1
Ayh Extension - Chrome 63.026.1
Dev
TVShow (227) 'CSA'
TVShow (228) 'APT'
TVProgram (83) 'BXT'
Miter Update(s)
Shim (Dictation)

Menu
Calendar
Project Tin (024/029)
Miter
RSS Feed
User Avatar
@vgmlr
=SUM(parts)