Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A lot of things that I don't remember #6

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d2007a0
Add @iconURL, @icon and @defaulticon
ponsfrilus Dec 12, 2018
2b8852c
Meta data improvements
ponsfrilus Dec 12, 2018
8b1e79f
Better script option with @conenct and @run-at
ponsfrilus Dec 12, 2018
3b3d2ad
Script rework
ponsfrilus Dec 12, 2018
8b4205d
Add link to every path of the unit
ponsfrilus Dec 12, 2018
bfe355c
Get userdata when logged-in
ponsfrilus Dec 12, 2018
322bb7b
[DONE] added new jquery version
richmartins May 15, 2020
46b051b
Retrieving DOM elements
JaavLex May 15, 2020
63b2206
WIP
nicolasreymond May 15, 2020
71f9d90
[DONE] added sciper to title
richmartins May 15, 2020
3483baf
[refactor] scipter added to title
ponsfrilus May 20, 2020
6647f38
[comfort] open admin data by default
ponsfrilus May 20, 2020
5151004
[todo] added
ponsfrilus May 20, 2020
3bd35b8
[feat] userscript specific content
ponsfrilus May 20, 2020
19fbb45
[F.T] Now admindata is unfolded by default with all languages
nicolasreymond May 27, 2020
adcf5a7
[F.T] Use people-API to get some user's info
nicolasreymond May 27, 2020
51b46ca
[feat] Mode list
ponsfrilus May 27, 2020
c34dc5c
[fix] Cache problem with GM.getValue and GM.setValue
ponsfrilus May 28, 2020
dcf30d7
[minor] beautifullage and ortho
ponsfrilus May 28, 2020
e39cddd
[feat] wait for results list before querying search-api
ponsfrilus May 28, 2020
b7afd99
[F.T] Connect to tequilla
nicolasreymond May 28, 2020
42f7a4e
[chore] constistancy
ponsfrilus May 28, 2020
c93f6c5
[swag] console.log art
ponsfrilus May 28, 2020
a005dda
[fix] use same querystring to query search API
ponsfrilus May 28, 2020
b10751f
[fix] jQuery as $
ponsfrilus May 28, 2020
c89269c
[feat] better list view handling
ponsfrilus May 28, 2020
d263153
[feat] better support for opening admin data link
ponsfrilus May 28, 2020
adf5501
[ver] bump to 1.5.4
ponsfrilus May 28, 2020
00efb2f
[feat] ensure that works on both people and personnes subdomain
ponsfrilus May 28, 2020
eabe68b
[chore] meta block reorganisation
ponsfrilus May 28, 2020
42adeac
[doc] README and CONTRIBUTING
ponsfrilus May 28, 2020
aea1568
Merge branch 'feature/NewPeoplePage'
ponsfrilus May 28, 2020
fc91f2d
[fix] multiple scipers displayed in search.epfl.ch
ponsfrilus May 29, 2020
9e9616e
[doc] TOC + image + cleanup
ponsfrilus May 29, 2020
0f6cce0
Merge pull request #5 from ponsfrilus/doc/README
ponsfrilus May 29, 2020
b3f4af7
[fix] people page
ponsfrilus Sep 24, 2021
f470b87
[feature] Add "plan.epfl.ch" as iframe for each accred
ponsfrilus Oct 1, 2021
33c50cd
[fix] plan iframe position
ponsfrilus Oct 1, 2021
a8ff018
[feature] add ♀ / ♂ information in details page
ponsfrilus Oct 4, 2022
7eb1201
[feature] add pic thumbnail in list
ponsfrilus Oct 6, 2022
94e48f2
[fix] people.epfl.ch/signatures is now exlcuded
ponsfrilus Jan 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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!
213 changes: 138 additions & 75 deletions EPFL_People.user.js
Original file line number Diff line number Diff line change
@@ -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("(<a href='" + unitHref + "'>#" + unitId + "</a>)");
}
});
});
// 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"]+'<br />');
});
$('.presentation').append('Sciper : ' + $.epfl_user["sciper"]+'<br />');

// 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('<h4>Mailing Lists</h4><div id="cadiMLdiv"><ul id="cadiML">cadiML</ul></div>');
$('#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('<br /><h4>Groups Lists</h4><div id="cadiGLdiv"><ul id="cadiGL">cadiGL</ul></div>');
$('#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(' <span class="sciperID">#' + usrObj.sciper + ' </span>')
}

let userPictureUrl = `https://people.epfl.ch/private/common/photos/links/${usrObj.sciper}.jpg?ts=${Date.now()}`
let imageElement = `<img id="pic${usrObj.sciper}" class="userPic" alt="" src="${userPictureUrl}" style="width:100%;max-width:37px" />`
$(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(' <span class="sciperID"></span>')
})
})
}
}

// 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')
$('<div class="d-flex flex-wrap justify-content-between align-items-baseline" id="EPFLPeopleUserScriptData"></div>').insertAfter('.container:first div:first')
$('#EPFLPeopleUserScriptData').css('font-family', 'monospace')
$('#EPFLPeopleUserScriptData').css('white-space', 'pre')
$('#EPFLPeopleUserScriptData').append('<div>sciper: ' + sciper + '</div>')
$('#EPFLPeopleUserScriptData').append('<div>username: ' + username + '</div>')
$('#EPFLPeopleUserScriptData').append('<div>email: ' + user.email + '</div>')
$('#EPFLPeopleUserScriptData').append('<div>unit: ' + user.accreds[0].path + '</div>')
for (accred in user.accreds) {
if (user.accreds[accred].officeList.length) {
for (office of user.accreds[accred].officeList) {
$(`#collapse-${accred}`).append(`<div><iframe id="userScript${accred}" height="350px" width="100%" src="https://plan.epfl.ch/iframe/?room==${office}&map_zoom=10"></iframe></div>`)
}
}
}
});
GM_addStyle("#cadiMLdiv{ padding-left: 20px; } #cadiML ul ul { margin-left: 10px; }" );
GM_addStyle("#cadiGLdiv{ padding-left: 20px; } #cadiGL ul ul { margin-left: 10px; }" );
}

});
46 changes: 30 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
# EPFL People UserScript
A Greasemonkey/Tampermonkey script to improve browsing on people.epfl.ch
<!-- TOC titleSize:2 tabSpaces:3 depthFrom:1 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 skip:1 title:0 charForUnorderedList:* -->
* [Installation](#installation)
* [Features](#features)
* [On search.epfl.ch](#on-searchepflch)
* [On people.epfl.ch](#on-peopleepflch)
* [Example](#example)
<!-- /TOC -->

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
Binary file added img/Kermit_profil.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed img/improvement-1.png
Binary file not shown.
Binary file removed img/improvement-1b.png
Binary file not shown.
Binary file removed img/improvement-2.png
Binary file not shown.