Skip to content

Fritidsbrug #4

@iklog

Description

@iklog

Hej Mathias

Flot app. Jeg har taget den i brug på min skole og den er meget effektiv - måske næsten for effektiv.

Som IT-vejleder, synes jeg, at det er vigtigt, at eleverne har mulighed for at bruge deres devices i fritiden også - gerne til spil og streaming.

Derfor vil jeg meget gerne lade admin tilføje perioder, hvor netshield ikke blokerer. Det kan være i frikvarterer eller efter skole.

Er det noget, du kunne tænke dig at føje til appen, eller skal jeg forke?

Jeg har spurgt Gemini om en løsning:

"Allow the superuser to add a list of time periods to the json in admin console. Within the time periods games, streaming and social media are allowed."

To implement time-based access for games, streaming, and social media, we need to update both the configuration schema and the logic in the background script. This will allow the superuser to define specific windows where certain blocks are bypassed.

1. Update schema.json

You need to add a new property to the schema to define these "Golden Hours." This uses an array of objects to define start and end times.

"allowanceWindows": {
  "type": "array",
  "title": "Tidsrum for Afslapning (Spil & Streaming)",
  "description": "Definer tidsrum (f.eks. 14:00-16:00) hvor blokeringer for underholdning deaktiveres.",
  "items": {
    "type": "object",
    "properties": {
      "start": { "type": "string", "description": "Format HH:MM (f.eks. 14:00)" },
      "end": { "type": "string", "description": "Format HH:MM (f.eks. 16:00)" }
    }
  }
}

2. Update background.js Logic

We need a helper function to check if the current time falls within any of the allowed windows. Then, we modify reloadRules to conditionally skip adding certain block rules.

Step A: Time Check Helper

Add this function to the bottom of your background.js:

function isCurrentlyAllowed(windows) {
    if (!windows || windows.length === 0) return false;
    
    const now = new Date();
    const currentTime = now.getHours() * 60 + now.getMinutes();

    return windows.some(win => {
        const [sH, sM] = win.start.split(':').map(Number);
        const [eH, eM] = win.end.split(':').map(Number);
        const startTotal = sH * 60 + sM;
        const endTotal = eH * 60 + eM;
        return currentTime >= startTotal && currentTime <= endTotal;
    });
}

Step B: Integrate into reloadRules

Modify the beginning of your reloadRules function to fetch the new setting and check the time:

async function reloadRules() {
    let items = await chrome.storage.managed.get({
        remoteBlocklistUrl: '',
        remoteAllowlistUrl: '',
        adminBlockedRegex: [],
        adminSuperAllowlist: [],
        allowanceWindows: [] // Hent de nye tidsrum
    });

    const relaxTime = isCurrentlyAllowed(items.allowanceWindows);
    
    // ... rest of the setup code ...

    // Kun tilføj blokeringer hvis det IKKE er "relaxTime"
    if (!relaxTime) {
        blockedSites.forEach(function(site) {
            newRules.push({
                id: nextId,
                priority: 1,
                action: redirectObj,
                condition: { regexFilter: ".*" + site + ".*", resourceTypes: ['main_frame'] }
            });
            nextId++;
        });
    }
    
    // Fortsæt med adminSuperAllowlist (Priority 4) som altid skal køre
}

Summary of Changes

  • Schema: Added allowanceWindows so admins can set time ranges in the Google Admin Console.
  • Logic: The isCurrentlyAllowed function calculates the current minute of the day and compares it against the admin's list.
  • Behavior: If the current time matches a window, the script skips adding the blockedSites and remoteBlock rules to the firewall, effectively "opening" the web for that duration.

Eksempel: Frikvarter og Efterskole-tid
Dette eksempel åbner for adgang i et kort frikvarter om formiddagen og igen i en længere periode om eftermiddagen.

JSON
"allowanceWindows": [
  {
    "start": "10:15",
    "end": "10:45"
  },
  {
    "start": "14:00",
    "end": "16:30"
  },
  {
    "start": "19:00",
    "end": "21:00"
  }
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions