Skip to content

Commit

Permalink
Merge pull request #5 from 69/master
Browse files Browse the repository at this point in the history
truncate long usernames
  • Loading branch information
sad authored Oct 4, 2019
2 parents d4ce7e0 + 06d5890 commit 1bf9034
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 4 additions & 10 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
chrome.extension.onMessage.addListener((request, sender, sendResponse) => {
if (request.name === 'forceLogout') {
if (request.method === 'forceLogout') {
chrome.cookies.remove({
url: 'https://api-auth.soundcloud.com/connect/',
name: '_session_auth_key',
}, () => sendResponse(true));
}

if (request.name === 'getCookie') {
} else if (request.method === 'getCookie') {
chrome.cookies.get({
url: 'https://soundcloud.com/',
name: request.data.name,
}, (cookie) => sendResponse(cookie));
}

if (request.name === 'setCookie') {
} else if (request.method === 'setCookie') {
chrome.cookies.set({
url: 'https://soundcloud.com/',
name: request.data.name,
value: request.data.value,
secure: true,
}, (cookie) => sendResponse(cookie));
}

if (request.name === 'removeCookie') {
} else if (request.method === 'removeCookie') {
chrome.cookies.remove({
url: 'https://soundcloud.com/',
name: request.data.name,
Expand Down
14 changes: 10 additions & 4 deletions src/switcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ const deleteSession = (username) => {

const saveCurrentSession = () => {
const username = getCurrentUser();
chrome.runtime.sendMessage({ name: 'getCookie', data: { name: 'oauth_token' } }, (data) => {
chrome.runtime.sendMessage({ method: 'getCookie', data: { name: 'oauth_token' } }, (data) => {
const cookie = data.value;
if (username) saveSession(username, cookie);
});
};

const switchSession = (user) => {
saveCurrentSession();
chrome.runtime.sendMessage({ name: 'setCookie', data: { name: 'oauth_token', value: getSession(user) } }, () => {
chrome.runtime.sendMessage({ method: 'setCookie', data: { name: 'oauth_token', value: getSession(user) } }, () => {
location.reload();
});
};

const forceLogout = () => {
saveCurrentSession();
chrome.runtime.sendMessage({ name: 'removeCookie', data: { name: 'oauth_token' } }, () => {
chrome.runtime.sendMessage({ name: 'forceLogout' }, () => {
chrome.runtime.sendMessage({ method: 'removeCookie', data: { name: 'oauth_token' } }, () => {
chrome.runtime.sendMessage({ method: 'forceLogout' }, () => {
window.location = 'https://soundcloud.com/signin';
});
});
Expand Down Expand Up @@ -87,8 +87,13 @@ const injectSwitcher = () => {
link.id = 'switch-account';
link.dataset.user = account;
link.href = '#';
link.title = account;
link.style.display = 'inline-block';
link.style.width = '50%';
link.style.textOverflow = 'ellipsis';
link.style.overflow = 'hidden';
link.style.verticalAlign = 'middle';


const delBtn = document.createElement('a');

Expand All @@ -99,6 +104,7 @@ const injectSwitcher = () => {
delBtn.href = '#';
delBtn.style.padding = '5px';
delBtn.style.display = 'inline-block';
delBtn.style.verticalAlign = 'middle';

delBtn.onclick = (event) => {
if (confirm(`Are you sure you want to remove the '${event.target.dataset.user}' account?`)) { // eslint-disable-line
Expand Down

0 comments on commit 1bf9034

Please sign in to comment.