diff --git a/.release-please-manifest.json b/.release-please-manifest.json
index cd451e1..2b02a05 100644
--- a/.release-please-manifest.json
+++ b/.release-please-manifest.json
@@ -1,3 +1,3 @@
{
- ".": "1.37.1"
+ ".": "1.38.0"
}
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d0c356c..ee86265 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,12 @@
# Changelog
+## [1.38.0](https://github.com/YorikHansen/better-moodle/compare/1.37.4...1.38.0) (2024-06-17)
+
+
+### Features
+
+* **quickRoleChange:** Make switching roles as easy as switching lang ([#215](https://github.com/jxn-30/better-moodle/issues/215)) ([6aac352](https://github.com/YorikHansen/better-moodle/commit/6aac35237c4033964f159d5553ac15ad99aae01f))
+
## [1.37.4](https://github.com/YorikHansen/better-moodle/compare/1.37.3...1.37.4) (2024-06-14)
diff --git a/package.json b/package.json
index e4d07c8..8a832ec 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "uzl-better-moodle",
"description": "Improves the new weird Moodle 4 UI on UzL-Moodle",
- "version": "1.37.1",
+ "version": "1.38.0",
"packageManager": "yarn@4.3.0",
"type": "module",
"private": true,
@@ -10,14 +10,14 @@
"prettier:write": "prettier --write --cache --cache-strategy content ."
},
"devDependencies": {
- "@eslint/js": "9.4.0",
+ "@eslint/js": "9.5.0",
"@types/eslint": "8.56.10",
"@types/tampermonkey": "5.0.3",
"darkreader": "4.9.86",
- "eslint": "9.4.0",
+ "eslint": "9.5.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-userscripts": "0.5.3",
- "globals": "15.4.0",
+ "globals": "15.5.0",
"prettier": "3.3.2",
"userscript-meta": "1.0.1"
}
diff --git a/redesign.user.js b/redesign.user.js
index 13c7f9f..1861028 100644
--- a/redesign.user.js
+++ b/redesign.user.js
@@ -2,6 +2,7 @@
// @name 🎓️ CAU: better-moodle
// @namespace https://better-moodle.yorik.dev
// @ x-release-please-start-version
+// @version 1.38.0
// @version 1.37.4
// @ x-release-please-end
// @author Jan (jxn_30), Yorik (YorikHansen)
@@ -114,6 +115,11 @@ const TRANSLATIONS = {
},
},
},
+ quickRoleChange: {
+ defaultSwitchRole: 'Zur Moodle Rollenwechsel-Seite gehen',
+ goBack: 'Zurück zum Nutzermenü',
+ roleSelector: 'Rollen-Auswahl',
+ },
modals: {
settings: {
title: 'Einstellungen',
@@ -347,6 +353,11 @@ Viele Grüße
trans: 'Transgender',
},
},
+ quickRoleChange: {
+ name: 'Schneller Rollenwechsel',
+ description:
+ 'Ermöglicht es (mit den passenden Berechtigungen), die Betrachtung eines Kurses mit einer anderen Rolle direkt über das Profil-Dropdown zu ändern.',
+ },
},
darkmode: {
_title: 'Darkmode',
@@ -607,6 +618,11 @@ Viele Grüße
},
},
},
+ quickRoleChange: {
+ defaultSwitchRole: 'Go to Moodle switch role page',
+ goBack: 'Go back to user menu',
+ roleSelector: 'Role selector',
+ },
modals: {
settings: {
title: 'Preferences',
@@ -843,6 +859,11 @@ Best regards
trans: 'Transgender',
},
},
+ quickRoleChange: {
+ name: 'Quick role change',
+ description:
+ 'Allows (with the appropriate permissions) to change the view of a course with a different role directly via the profile dropdown.',
+ },
},
darkmode: {
_title: 'Darkmode',
@@ -2800,6 +2821,7 @@ const SETTINGS = [
'gay',
'trans',
]),
+ new BooleanSetting('general.quickRoleChange', true),
'darkmode',
$t('settings.darkmode._description'),
new SelectSetting('darkmode.mode', 'off', ['off', 'on', 'auto']).onInput(
@@ -2923,6 +2945,7 @@ const existingSettings = new Set([
'general.speiseplan',
'general.googlyEyes',
'general.semesterzeiten',
+ 'general.quickRoleChange',
'darkmode.mode',
'darkmode.brightness',
'darkmode.contrast',
@@ -4883,6 +4906,98 @@ const updateDarkReaderMode = (live = false) => {
updateDarkReaderMode();
// endregion
+// region Feature: general.quickRoleChange
+if (getSetting('general.quickRoleChange')) {
+ ready(() => {
+ const usermenu = document.getElementById('usermenu-carousel');
+ const usermenuInner = usermenu?.querySelector('.carousel-inner');
+ const roleSelectBtn = usermenu?.querySelector(
+ '.dropdown-item[href*="switchrole.php"]'
+ );
+ if (!roleSelectBtn) return;
+
+ const rolesUrl = roleSelectBtn.href;
+ fetch(rolesUrl)
+ .then(response => response.text())
+ .then(html => {
+ const parser = new DOMParser();
+ const doc = parser.parseFromString(html, 'text/html');
+ return doc.querySelectorAll('form[action*="switchrole.php"]');
+ })
+ .then(forms => {
+ const roles = [];
+ forms.forEach(form => {
+ const role = {
+ id: form.querySelector('input[name="id"]').value,
+ switchrole: form.querySelector(
+ 'input[name="switchrole"]'
+ ).value,
+ returnurl: form.querySelector('input[name="returnurl"]')
+ .value,
+ sesskey: form.querySelector('input[name="sesskey"]')
+ .value,
+ title: form.querySelector('button').textContent,
+ };
+ roles.push(role);
+ });
+ return roles;
+ })
+ .then(roles => {
+ if (roles.length === 0) return;
+
+ const roleSelecotrItemId = PREFIX('role-selector-item');
+ const roleSelectorItem = document.createElement('div');
+ roleSelectorItem.id = roleSelecotrItemId;
+ roleSelectorItem.classList.add('carousel-item', 'submenu');
+ roleSelectorItem.setAttribute('role', 'menu');
+ roleSelectorItem.setAttribute(
+ 'aria-label',
+ $t('quickRoleChange.roleSelector')
+ );
+ roleSelectorItem.setAttribute('tabindex', -1);
+
+ roleSelectorItem.innerHTML = `
+
+
+
+
+ ${Object.entries(roles)
+ .map(
+ ([, role]) => `
+
+ `
+ )
+ .join('')}
+
+
+
+
+ `;
+
+ usermenuInner?.append(roleSelectorItem);
+
+ roleSelectBtn.href = '#';
+ roleSelectBtn.classList.add('carousel-navigation-link');
+ roleSelectBtn.dataset.carouselTargetId = roleSelecotrItemId;
+ });
+ });
+}
+// endregion
+
// region Feature: Dashboard right sidebar
// add a right sidebar with timeline and upcoming events on Dashboard
// if (isDashboard) {
diff --git a/yarn.lock b/yarn.lock
index 98de5d6..79eec79 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -23,14 +23,14 @@ __metadata:
languageName: node
linkType: hard
-"@eslint/config-array@npm:^0.15.1":
- version: 0.15.1
- resolution: "@eslint/config-array@npm:0.15.1"
+"@eslint/config-array@npm:^0.16.0":
+ version: 0.16.0
+ resolution: "@eslint/config-array@npm:0.16.0"
dependencies:
- "@eslint/object-schema": "npm:^2.1.3"
+ "@eslint/object-schema": "npm:^2.1.4"
debug: "npm:^4.3.1"
minimatch: "npm:^3.0.5"
- checksum: 10c0/60947a188157f2f811cc2aedf3c2494fa10932178838f6a7c7e9a8bb106ab51b4b4e571f49ae63cdd3884002b78631e4395be25d4ae52470360fc7fb463303d2
+ checksum: 10c0/b9d04409151dc95ec6b5e04e1e185a808d58e18cfc7340adc1e9420a5ff15843a0a308fb2cd9a2b354652885c2bebbcd5515814e93e9c9133f423891b6e53c70
languageName: node
linkType: hard
@@ -51,17 +51,17 @@ __metadata:
languageName: node
linkType: hard
-"@eslint/js@npm:9.4.0":
- version: 9.4.0
- resolution: "@eslint/js@npm:9.4.0"
- checksum: 10c0/7ffc508d3e9cd496cab7f08c5ba8f97851c8adaea3ebff8804b1c3b4662aa7aac7e9c3b597f7e47fdc29319a107bcf892865070a6b113c2e4d19f8fa1f99f569
+"@eslint/js@npm:9.5.0":
+ version: 9.5.0
+ resolution: "@eslint/js@npm:9.5.0"
+ checksum: 10c0/dacf51ec2d5b4c8d1315d21a0ff761235d9e39b2391cb945138c58dc512a6c18949c40b644235f5c4fdf5b637ef8f881214acc496dddf46b718529bf22af42ac
languageName: node
linkType: hard
-"@eslint/object-schema@npm:^2.1.3":
- version: 2.1.3
- resolution: "@eslint/object-schema@npm:2.1.3"
- checksum: 10c0/ee892d0112ee7ec86312dfb1fa718da76b2d446e3495b9ec1f3ef31382a335d31420b76f3def175b96f7c3517c88fc860fec049d62a81d444237a23881559403
+"@eslint/object-schema@npm:^2.1.4":
+ version: 2.1.4
+ resolution: "@eslint/object-schema@npm:2.1.4"
+ checksum: 10c0/e9885532ea70e483fb007bf1275968b05bb15ebaa506d98560c41a41220d33d342e19023d5f2939fed6eb59676c1bda5c847c284b4b55fce521d282004da4dda
languageName: node
linkType: hard
@@ -147,11 +147,11 @@ __metadata:
linkType: hard
"acorn@npm:^8.11.3":
- version: 8.11.3
- resolution: "acorn@npm:8.11.3"
+ version: 8.12.0
+ resolution: "acorn@npm:8.12.0"
bin:
acorn: bin/acorn
- checksum: 10c0/3ff155f8812e4a746fee8ecff1f227d527c4c45655bb1fad6347c3cb58e46190598217551b1500f18542d2bbe5c87120cb6927f5a074a59166fbdd9468f0a299
+ checksum: 10c0/a19f9dead009d3b430fa3c253710b47778cdaace15b316de6de93a68c355507bc1072a9956372b6c990cbeeb167d4a929249d0faeb8ae4bb6911d68d53299549
languageName: node
linkType: hard
@@ -337,15 +337,15 @@ __metadata:
languageName: node
linkType: hard
-"eslint@npm:9.4.0":
- version: 9.4.0
- resolution: "eslint@npm:9.4.0"
+"eslint@npm:9.5.0":
+ version: 9.5.0
+ resolution: "eslint@npm:9.5.0"
dependencies:
"@eslint-community/eslint-utils": "npm:^4.2.0"
"@eslint-community/regexpp": "npm:^4.6.1"
- "@eslint/config-array": "npm:^0.15.1"
+ "@eslint/config-array": "npm:^0.16.0"
"@eslint/eslintrc": "npm:^3.1.0"
- "@eslint/js": "npm:9.4.0"
+ "@eslint/js": "npm:9.5.0"
"@humanwhocodes/module-importer": "npm:^1.0.1"
"@humanwhocodes/retry": "npm:^0.3.0"
"@nodelib/fs.walk": "npm:^1.2.8"
@@ -357,7 +357,7 @@ __metadata:
eslint-scope: "npm:^8.0.1"
eslint-visitor-keys: "npm:^4.0.0"
espree: "npm:^10.0.1"
- esquery: "npm:^1.4.2"
+ esquery: "npm:^1.5.0"
esutils: "npm:^2.0.2"
fast-deep-equal: "npm:^3.1.3"
file-entry-cache: "npm:^8.0.0"
@@ -377,7 +377,7 @@ __metadata:
text-table: "npm:^0.2.0"
bin:
eslint: bin/eslint.js
- checksum: 10c0/826c901812536451e1bdb151359098db3a01ee9ff41775d5e97553626d07f7319cb2a0fd54176ef8e2e057105874077426b5d408ee6e8cff06bb814651f4c004
+ checksum: 10c0/1c83d94ccfd6d97474aaaf463714eba7afa040639ad9191db430d34e9e2851ba14510651de69b52f26ee30611caf0fa4c66b3fb73bb71df6ab10cef5bb44bb32
languageName: node
linkType: hard
@@ -392,7 +392,7 @@ __metadata:
languageName: node
linkType: hard
-"esquery@npm:^1.4.2":
+"esquery@npm:^1.5.0":
version: 1.5.0
resolution: "esquery@npm:1.5.0"
dependencies:
@@ -499,10 +499,10 @@ __metadata:
languageName: node
linkType: hard
-"globals@npm:15.4.0":
- version: 15.4.0
- resolution: "globals@npm:15.4.0"
- checksum: 10c0/19041b8fd49deb154e1cb706c82756ab7184c8ae3495aab183efcad9edd1b6320cc54af1a9110d8699245bef124834b004a8156ca988ba7814c25ec71a43f6a4
+"globals@npm:15.5.0":
+ version: 15.5.0
+ resolution: "globals@npm:15.5.0"
+ checksum: 10c0/f13c3cb0c6d49b9d23e447b86e33ca6139753087060c3063863c0dd2b5d79f4a114c48d20e321916e6c3701adb3f6b67d6ac8d8ed2bae6da45482c968532d4e2
languageName: node
linkType: hard
@@ -858,14 +858,14 @@ __metadata:
version: 0.0.0-use.local
resolution: "uzl-better-moodle@workspace:."
dependencies:
- "@eslint/js": "npm:9.4.0"
+ "@eslint/js": "npm:9.5.0"
"@types/eslint": "npm:8.56.10"
"@types/tampermonkey": "npm:5.0.3"
darkreader: "npm:4.9.86"
- eslint: "npm:9.4.0"
+ eslint: "npm:9.5.0"
eslint-config-prettier: "npm:9.1.0"
eslint-plugin-userscripts: "npm:0.5.3"
- globals: "npm:15.4.0"
+ globals: "npm:15.5.0"
prettier: "npm:3.3.2"
userscript-meta: "npm:1.0.1"
languageName: unknown