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

Add other websites from the StackExchange network to the StackExchange implementation #110 #114

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ document.addEventListener('DOMContentLoaded', () => {
return new TwitterHover(node, getDomain(CURRENT_TAB));
case 'stackoverflow.com':
return new StackExchangeHover(node, getDomain(CURRENT_TAB));
case 'stackexchange.com':
return new StackExchangeHover(node, getDomain(CURRENT_TAB));
case 'soundcloud.com':
return new SoundCloudHover(node, getDomain(CURRENT_TAB));

Expand Down
12 changes: 5 additions & 7 deletions js/templates/stackexchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@ class StackExchangeHover {

/* Takes {String} link
* Returns {String} link
* Description: Returns the domain name associated to a full link
* Description: Returns the site name associated to a full link (e.g. stackoverflow, physics)
*/
getDomain(link) {
let subdomains = link.replace('http://', '').replace('https://', '').split('/')[0].split('.').length;
return link.replace('http://', '').replace('https://', '').split('/')[0].split('.').slice(subdomains - 2, subdomains).join('.');
getSite(link) {
return link.replace('http://', '').replace('https://', '').split('/')[0].split('.')[0];
}

/* Description: This function is unique to every Hover class,
* its goal is to get how many accepted answer are they .
* it can also give the code of the accepted answer.
*/
checkLinkType() {
// TODO: Make sure the website is not part of the stackexchange network and not limit ourselves to stackoverflow
if (this.CURRENT_TAB != 'stackoverflow.com' && this.redirectLink.includes('/questions/')) {
if (this.CURRENT_TAB != 'stackoverflow.com' && this.CURRENT_TAB != 'stackexchange.com' && this.redirectLink.includes('/questions/')) {
return 'question';
} else {
return 'unknown';
Expand All @@ -37,7 +35,7 @@ class StackExchangeHover {

// Get the question ID and website from the URL
const questionID = node.href.split('/questions/')[1].split('/')[0];
const site = this.getDomain(node.href).split('.')[0];
const site = this.getSite(node.href);

if (questionID) {

Expand Down