diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..50b3138
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,36 @@
+# Contributing
+
+
+♥ We love pull requests from everyone !
+
+
+When contributing to this repository, please first discuss the change you wish
+to make via issue, email, or any other method with the owners of this repository
+before making a change.
+
+
+## So all code changes happen through Pull Requests
+
+Pull requests are the best way to propose changes to the codebase. We actively
+welcome your pull requests:
+
+1. Fork the repo and create your branch from `master`.
+2. If you've added code that should be tested, add tests.
+3. If you've added code that need documentation, update the documentation.
+4. Be sure to test your modifications.
+5. Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
+6. Issue that pull request!
+
+
+## Report bugs using Github's [issues](https://github.com/ponsfrilus/EPFL_People_UserScript/issues)
+
+We use GitHub issues to track public bugs. Report a bug by [opening a new
+issue](https://github.com/ponsfrilus/EPFL_People_UserScript/issues/new); it's
+that easy!
+
+## Feature reuqest using Github's [issues](https://github.com/ponsfrilus/EPFL_People_UserScript/issues)
+
+We use GitHub issues to collect feature requests.
+Add a feature reeqeuest by [opening a new
+issue](https://github.com/ponsfrilus/EPFL_People_UserScript/issues/new); it's
+that easy!
\ No newline at end of file
diff --git a/EPFL_People.user.js b/EPFL_People.user.js
index 28f5e17..257f45a 100644
--- a/EPFL_People.user.js
+++ b/EPFL_People.user.js
@@ -1,87 +1,150 @@
// ==UserScript==
// @name EPFL People
-// @namespace none
+// @version 1.9.0
// @description A script to improve browsing on people.epfl.ch
+// @author EPFL-dojo
+// @namespace EPFL-dojo
// @include https://people.epfl.ch/*
+// @exclude https://people.epfl.ch/signatures/*
// @include https://personnes.epfl.ch/*
-// @version 1.3
-// @grant GM_xmlhttpRequest
-// @grant GM_addStyle
-// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
-// @author EPFL-dojo
-// @downloadURL https://raw.githubusercontent.com/epfl-dojo/EPFL_People_UserScript/master/EPFL_People.user.js
+// @include https://search.epfl.ch/?filter=people&*
+// @require https://code.jquery.com/jquery-3.5.1.min.js
+// @downloadURL https://raw.githubusercontent.com/ponsfrilus/EPFL_People_UserScript/master/EPFL_People.user.js
// ==/UserScript==
-//Avoid conflicts
-this.$ = this.jQuery = jQuery.noConflict(true);
-$(document).ready(function() {
- function absURL(url, needle, replacement) {
- return url.replace(needle, replacement);
- }
-
- // get the h1 name content
- $.epfl_user = {
- "name": $("h1").text(),
- "sciper": $('a[href*="https://people.epfl.ch/cgi-bin/people?id="]').attr('href').match(/id=([0-9]{6})/)[1]
- };
-
- $.epfl_user.rooms = $('a[href*="http://plan.epfl.ch/?room="]').map(function() {
- return this.text;
- }).toArray();
-
- $('span.unit-name').each(function(){
- var that = $(this);
- var unitName = that.parent().find('a').last().text();
- GM_xmlhttpRequest({
- method: "GET",
- url: "https://search.epfl.ch/ubrowse.action?acro=" + unitName,
- onload: function(response) {
- var html = $.parseHTML( response.responseText );
- var unitHref = $(html).find('a[href*="http://infowww.epfl.ch/imon-public/OrgUnites.detail?ww_i_unite="]').attr('href');
- var unitId = unitHref.match(/ww_i_unite=([0-9]{4,6})/)[1];
- that.parent().parent().parent().append("(#" + unitId + ")");
- }
- });
- });
+// TODO: [ ] get the groups
+// TODO: [ ] get the mailinglist
+// TODO: [ ] Add a modal with userscript info (https://epfl-si.github.io/elements/#/organisms/modal)
- // change the main title content to add the sciper in it
- $("h1").text($.epfl_user["name"] + " #" + $.epfl_user["sciper"] + " ()");
- $.get("/cgi-bin/people/showcv?id=" + $.epfl_user["sciper"] + "&op=admindata&type=show&lang=en&cvlang=en", function(data){
- $.epfl_user["username"] = data.match(/Username: (\w+)\s/)[1];
- $("h1").text($.epfl_user["name"] + " #" + $.epfl_user["sciper"] + " (" + $.epfl_user["username"]+ ")");
- $('.presentation').append('Username : ' + $.epfl_user["username"]+'
');
- });
- $('.presentation').append('Sciper : ' + $.epfl_user["sciper"]+'
');
-
- // Add user's mailing list in the right column
- var cadiURL = 'http://cadiwww.epfl.ch/listes?sciper='+$.epfl_user["sciper"];
- GM_xmlhttpRequest({
- method: "GET",
- url: cadiURL,
- onload: function(response) {
- html = $.parseHTML( response.responseText );
- // Mailing list emails
- mailinglistUL = $(html).contents('ul').not(':last');
- if (0 < mailinglistUL.length) {
- $('.right-col').append('
Mailing Lists
');
- $('#cadiML').html(mailinglistUL);
- // replace cadi's relative URL with absolute URL
- $('#cadiML a').each(function(){
- this.href = absURL(this.href, window.location.origin, 'http://cadiwww.epfl.ch');
- });
+$(document).ready(async () => {
+
+ console.log("%cCoded by EPFL-DOJO","color:#060;font-weight:bold;"),
+ console.log("%cPlease visit https://github.com/epfl-dojo/\nand checkout-out EPFL Userscripts here\nhttps://github.com/search?q=topic:epfl-userscript&type=Repositories\n\nFeel free to contribute (https://github.com/epfl-dojo/EPFL_People_UserScript) and add issues or feature request here\nhttps://github.com/epfl-dojo/EPFL_People_UserScript/issues","color:#08ff00;font-weight:bold;"),
+ console.log("%c ⊂(◉‿◉)つ","font-size:34px; line-height:1.4em;");
+
+ // Async function to get people's data from search-api
+ const getPeopleFromSearchAPI = async function (needle) {
+ var searchURL = 'https://search-api.epfl.ch/api/ldap?q=' + encodeURIComponent(needle) + '&showall=0&hl=en&pageSize=all&siteSearch=people.epfl.ch'
+ var result = await $.ajax({
+ type: 'GET',
+ url: searchURL,
+ async: true,
+ success: function (data) {
+ result = data
}
- // Group list emails
- grouplistUL = $(html).contents('ul').last();
- if (0 < grouplistUL.length) {
- $('.right-col').append('
Groups Lists
');
- $('#cadiGL').html(grouplistUL);
- // replace cadi's relative URL with absolute URL
- $('#cadiGL a').each(function(){
- this.href = absURL(this.href, window.location.origin, 'http://cadiwww.epfl.ch');
- });
+ })
+ return result
+ }
+
+ const waitForEl = function (selector, callback) {
+ if ($(selector).length) {
+ callback()
+ } else {
+ setTimeout(function () {
+ waitForEl(selector, callback)
+ }, 100)
+ }
+ }
+
+ const updateSearchResultsList = async (q) => {
+ // Query search-api for users
+ let users = await getPeopleFromSearchAPI(q)
+ console.log(users)
+ // In case we get some users
+ if (typeof users !== 'undefined') {
+ // Wait for the results element with class '.list-unstyled'
+ waitForEl('.list-unstyled', async () => {
+ // For each results
+ $('h3[class=h3] > a[class=result]').each(function(index, value) {
+ // Find the email (not all users have one, but for now it's the quickest way to get a unique identifier)
+ let usrEmail = $(this).parents('div[class=result]').find('a').last().html()
+ // Lookup in users which entry match this email
+ let usrObj = users.find(el => el.email === usrEmail)
+ // If nothing found, process the next element
+ if (typeof usrObj === 'undefined') {
+ return
+ }
+ // Have this user already have the span class sciperID (This can happen when using the search input)
+ let spanSciper = $(this).parents('h3').find('.sciperID')
+ if (spanSciper.length) {
+ // Found the span, replace the content
+ spanSciper.html('#' + usrObj.sciper)
+ } else {
+ // Span not found, insert it
+ $(this).after(' #' + usrObj.sciper + ' ')
+ }
+
+ let userPictureUrl = `https://people.epfl.ch/private/common/photos/links/${usrObj.sciper}.jpg?ts=${Date.now()}`
+ let imageElement = ``
+ $(this).parents('h3').html((i,ori) => {
+ return `${imageElement} ${ori}`
+ })
+ })
+ })
+ } else {
+ // Insert the span class sciperID for the next search
+ waitForEl('.list-unstyled', async () => {
+ $('h3[class=h3] > a[class=result]').each(function(index, value) {
+ $(this).after(' ')
+ })
+ })
+ }
+ }
+
+ // In case we are on https://search.epfl.ch/?filter=people&
+ if (document.URL.includes('https://search.epfl.ch')) {
+ console.log('Mode: list')
+ const q = new URLSearchParams(window.location.search).get('q')
+ console.debug("Looking for", q)
+ updateSearchResultsList(q)
+ $('input[name=search]').on('input', (e) => {
+ updateSearchResultsList($('input[name=search]').val())
+ })
+ }
+
+ // In case we are on https://people.epfl.ch/* or https://personnes.epfl.ch/*
+ if (document.URL.includes('https://people.epfl.ch/') || document.URL.includes('https://personnes.epfl.ch/')) {
+ console.log('Mode: details')
+
+ let adminDataLink = $('a:contains("Administrative data"),a:contains("Données administratives")')
+ if (adminDataLink.length) {
+ adminDataLink[0].click()
+ }
+ // Comfort, open admindata by default
+ unsafeWindow.toggleVis('admin-data')
+
+ const name = $('h1#name').text()
+ const sex = ($('h1#name').attr('class').includes('pnf')) ? '♀' : '♂'
+ const users = await getPeopleFromSearchAPI(name)
+ if (users.length != 1) {
+ console.error(`⚠ Watchout: ${((users.length > 1) ? 'more than one user' : 'no user')} found!`)
+ }
+ const user = users[0]
+ // console.debug(user)
+ const sciper = user.sciper
+ const username = $('dt:contains("Username")').next('dd').html()
+
+ // Modify the main title adding sex and sciper
+ $('h1#name').text((i,ori) => {
+ return `${sex} ${ori} #${sciper}`
+ })
+
+ // Create a new div to host specific content of this script
+ $('.container:first > div > h1.mr-3').css('margin-bottom', '0px')
+ $('').insertAfter('.container:first div:first')
+ $('#EPFLPeopleUserScriptData').css('font-family', 'monospace')
+ $('#EPFLPeopleUserScriptData').css('white-space', 'pre')
+ $('#EPFLPeopleUserScriptData').append('sciper: ' + sciper + '
')
+ $('#EPFLPeopleUserScriptData').append('username: ' + username + '
')
+ $('#EPFLPeopleUserScriptData').append('email: ' + user.email + '
')
+ $('#EPFLPeopleUserScriptData').append('unit: ' + user.accreds[0].path + '
')
+ for (accred in user.accreds) {
+ if (user.accreds[accred].officeList.length) {
+ for (office of user.accreds[accred].officeList) {
+ $(`#collapse-${accred}`).append(``)
+ }
}
}
- });
- GM_addStyle("#cadiMLdiv{ padding-left: 20px; } #cadiML ul ul { margin-left: 10px; }" );
- GM_addStyle("#cadiGLdiv{ padding-left: 20px; } #cadiGL ul ul { margin-left: 10px; }" );
+ }
+
});
diff --git a/README.md b/README.md
index 7355b65..934ade5 100644
--- a/README.md
+++ b/README.md
@@ -1,27 +1,41 @@
# EPFL People UserScript
-A Greasemonkey/Tampermonkey script to improve browsing on people.epfl.ch
+
+* [Installation](#installation)
+* [Features](#features)
+ * [On search.epfl.ch](#on-searchepflch)
+ * [On people.epfl.ch](#on-peopleepflch)
+* [Example](#example)
+
+A user script to improve browsing on [search.epfl.ch] and [people.epfl.ch].
-Improvement
------------
-### Improvement #1
-Show the username and the sciper number in the title
+## Installation
-![Improvement #1](https://raw.githubusercontent.com/epfl-dojo/EPFL_People_UserScript/master/img/improvement-1.png)
-![Improvement #1b](https://raw.githubusercontent.com/epfl-dojo/EPFL_People_UserScript/master/img/improvement-1b.png)
+1. Install [Greasemonkey](https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/) (Firefox), [Tampermonkey](http://tampermonkey.net/) or [Violentmonkey](https://violentmonkey.github.io/);
+1. Open the RAW content of [EPFL_People.user.js](https://raw.githubusercontent.com/ponsfrilus/EPFL_People_UserScript/master/EPFL_People.user.js);
+1. Install and enable the script;
+1. Enjoy new features while browsing [people.epfl.ch](http://people.epfl.ch), e.g. [169419](http://go.epfl.ch/nbo).
-### Improvement #2
-Show the mailing lists that the user belong to
-![Improvement #3](https://raw.githubusercontent.com/epfl-dojo/EPFL_People_UserScript/master/img/improvement-2.png)
+## Features
+### On search.epfl.ch
+ * Add the sciper number next to the person's name
-Installation
-------------
+### On people.epfl.ch
-1. Install the Firefox add-on [Greasemonkey](https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/) or [Tampermonkey](http://tampermonkey.net/) for Chrome.
-1. Open the RAW content of [EPFL_People.user.js](https://raw.githubusercontent.com/epfl-dojo/EPFL_People_UserScript/master/EPFL_People.user.js)
-1. Install and enable the script
-1. Browse to someone on [people.epfl.ch](http://people.epfl.ch), e.g. [169419](http://go.epfl.ch/nbo)
+ * Add the sciper number next to the person's name
+ * Auto-load the login page if not logged
+ * Toggle the admin data information
+ * Display information such as sciper, username, email and unit just below the person's name
+
+
+## Example
+
+![Kermit_profil](./img/Kermit_profil.png)
+
+
+[search.epfl.ch]: https://search.epfl.ch
+[people.epfl.ch]: https://people.epfl.ch
\ No newline at end of file
diff --git a/img/Kermit_profil.png b/img/Kermit_profil.png
new file mode 100644
index 0000000..7ef9164
Binary files /dev/null and b/img/Kermit_profil.png differ
diff --git a/img/improvement-1.png b/img/improvement-1.png
deleted file mode 100644
index cf879b2..0000000
Binary files a/img/improvement-1.png and /dev/null differ
diff --git a/img/improvement-1b.png b/img/improvement-1b.png
deleted file mode 100644
index 4e018cc..0000000
Binary files a/img/improvement-1b.png and /dev/null differ
diff --git a/img/improvement-2.png b/img/improvement-2.png
deleted file mode 100644
index 99e027c..0000000
Binary files a/img/improvement-2.png and /dev/null differ