Skip to content

Commit a01e4dc

Browse files
committed
cleaning
1 parent 7990081 commit a01e4dc

3 files changed

Lines changed: 59 additions & 45 deletions

File tree

app/src/background.js

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,12 @@ export async function getStorageProperty (name) {
190190
}
191191

192192
export function newTab (url, settings) {
193-
log(':', { url })
193+
log({ url })
194194
chrome.tabs.create({ url: url })
195195
}
196196

197197
export function updateTab (url, settings) {
198-
log(': ', { url, settings })
198+
log({ url, settings })
199199
let tabId = get(settings, 'tabId')
200200
// || (get(settings, "tab").id || null;
201201
if (!tabId) {
@@ -208,7 +208,7 @@ export function updateTab (url, settings) {
208208
tabId = null
209209
}
210210
chrome.tabs.update(tabId, { url })
211-
log(': ', { tabId, url })
211+
log({ tabId, url })
212212
}
213213

214214
export async function sendUrlToTab (url, settings) {
@@ -279,7 +279,7 @@ export function removeUriHandler (url) {
279279
}
280280

281281
export function cleanDomain (domain) {
282-
if (!domain) return
282+
if (!domain) return null
283283
let cleanDomain = removeUriHandler(domain.toString())
284284
if (cleanDomain.includes('/')) {
285285
return cleanDomain.split('/')[0]
@@ -309,7 +309,7 @@ export async function search (query, settings) {
309309
let limit = get(settings, 'limit', { default: 10 })
310310
let instance = get(settings, 'instance') || (await getInstance())
311311
if (!instance || !query) {
312-
return
312+
return null
313313
}
314314
let url = getUrlOrNull(instance + 'api/v2/search')
315315
url.searchParams.append('q', query)
@@ -323,35 +323,30 @@ export function getCodeRedirectPath () {
323323
}
324324

325325
export async function setCode (url, settings) {
326-
// TODO:
327326
// https://hachyderm.io/oauth/authorize/native?code=6Z4BHNsk-ltNXBoMzlL_D28xYNE35ElYeXKTncATnbw
328327
let codeSplit = url.split('?')
329328
let instance = await getInstance()
330329

331330
log({ url, codeSplit, instance, settings })
331+
332332
if (instance + getCodeRedirectPath() == codeSplit[0]) {
333333
log('match', { url, codeSplit, instance, settings })
334334
updateTab(instance, settings)
335335
let code = codeSplit[1].split('=')[1]
336336
log('match', { code })
337337
await setStorageWithProperty('code', code)
338+
338339
return code
339340
} else {
340341
log('no match', { url, codeSplit, instance, settings })
341-
return
342-
}
343-
}
344342

345-
export async function getCode () {
346-
return getStorageProperty('code').then(result => {
347-
if (result) {
348-
return result
349-
}
350-
})
343+
return null
344+
}
351345
}
352346

353347
export function mastodonUrlResult (url, settings) {
354348
let result = { url, settings: {} }
349+
355350
if (settings) {
356351
Object.assign(result.settings, settings)
357352
delete settings.url
@@ -361,6 +356,7 @@ export function mastodonUrlResult (url, settings) {
361356
if (!result.pageType) {
362357
result.pageType = 'account'
363358
}
359+
364360
return result
365361
}
366362

@@ -378,6 +374,7 @@ export function makeMastodonUrl (
378374
// {instance: 'thedreaming.city', id: '109660728919305576', type: 'url-host'}
379375
// {instance: 'https://hachyderm.io/', id: '109660728945403082', type: 'local'
380376
// determine why this one cant be found what do then https://thedreaming.city/@paeneultima/109733736814167269
377+
381378
let url = [makeHttps(local).slice(0, -1), '@' + username]
382379

383380
if (remote) {
@@ -399,11 +396,18 @@ export function makeMastodonUrl (
399396

400397
let result = {
401398
accounts: [
402-
{ instance: remote || local, username, type: 'built', type: 'built' }
399+
{ instance: remote || local, username, type: 'built', url: url.join('/') }
403400
],
404401
statuses: !status
405402
? []
406-
: [{ instance: remote || local, id: status, type: 'built' }]
403+
: [
404+
{
405+
instance: remote || local,
406+
id: status,
407+
type: 'built',
408+
url: url.join('/')
409+
}
410+
]
407411
}
408412
log('result', { result, settings, url })
409413

@@ -547,7 +551,7 @@ export async function statuses (id, settings) {
547551
let instance = get(settings, 'instance') || (await getInstance())
548552

549553
if (!instance || !id) {
550-
return
554+
return null
551555
}
552556

553557
let url = getUrlOrNull(instance + 'api/v1/statuses/' + id)
@@ -872,7 +876,7 @@ export async function jumpMastodonUrl (url, settings) {
872876
let statusUrl = get(results, 'url')
873877

874878
if (!statusUrl) {
875-
return
879+
return null
876880
}
877881
let statusUrlObject = getUrlOrNull(statusUrl)
878882
let statusesArray = [
@@ -912,7 +916,7 @@ export async function jumpMastodonUrl (url, settings) {
912916
log('local to local') // ???
913917
// return makeMastodonUrl(
914918
// instance, username, null, status, subpath);
915-
return
919+
return null
916920
}
917921
} else {
918922
log('remote to local')
@@ -1062,7 +1066,9 @@ export async function setToken (settings) {
10621066
let url = getUrlOrNull(
10631067
get(settings, 'url', { default: (await getInstance()) + 'oauth/token' })
10641068
)
1065-
let code = get(settings, 'code', { default: await getCode() })
1069+
let code = get(settings, 'code', {
1070+
default: await getStorageProperty('code')
1071+
})
10661072
let client_id = get(settings, 'client_id', {
10671073
default: await getStorageProperty('client_id')
10681074
})
@@ -1157,7 +1163,7 @@ export async function jumpMastodonTab (tab, settings) {
11571163
return jumpMastodonUrl(tab.url, settings).then(async result => {
11581164
if (!result) {
11591165
log('no result')
1160-
return
1166+
return null
11611167
}
11621168

11631169
if (get(settings, 'locality') == 'remote-remote') {
@@ -1186,7 +1192,7 @@ export async function jumpMastodonTab (tab, settings) {
11861192

11871193
if (!result) {
11881194
log('no result')
1189-
return
1195+
return null
11901196
}
11911197

11921198
settings = settings || {}
@@ -1313,7 +1319,7 @@ export async function onInstalled (installInfo) {
13131319
chrome.runtime.openOptionsPage()
13141320
} else {
13151321
log('newTab')
1316-
newTab(getChromeUrl('options.html'))
1322+
newTab(getChromeUrl('src/options.html'))
13171323
}
13181324
} else {
13191325
log('no major version change')
@@ -1435,7 +1441,7 @@ export async function onUpdated (tabId, changeInfo, tab) {
14351441

14361442
if (!tab) {
14371443
log('no tab')
1438-
return
1444+
return null
14391445
}
14401446

14411447
if (!tab.url) {
@@ -1454,7 +1460,7 @@ export async function onUpdated (tabId, changeInfo, tab) {
14541460
changeInfo,
14551461
tab
14561462
})
1457-
return
1463+
return null
14581464
} else {
14591465
log('tab is not populated', {
14601466
tabId,
@@ -1474,25 +1480,25 @@ export async function onUpdated (tabId, changeInfo, tab) {
14741480
changeInfo,
14751481
tab
14761482
})
1477-
return
1483+
return null
14781484
}
14791485
})
14801486
}
14811487
}
14821488

14831489
if (!tab.url) {
14841490
log('no tab.url')
1485-
return
1491+
return null
14861492
}
14871493

14881494
if (tab.url.indexOf('https://') !== 0 && tab.url.indexOf('http://') !== 0) {
14891495
log('not http(s)', tab.url)
1490-
return
1496+
return null
14911497
}
14921498

14931499
if (tab.url.indexOf('chrome://') === 0) {
14941500
log('chrome://', tab.url)
1495-
return
1501+
return null
14961502
}
14971503

14981504
if (tab.url.indexOf(getCodeRedirectPath()) > -1) {
@@ -1501,12 +1507,12 @@ export async function onUpdated (tabId, changeInfo, tab) {
15011507
let token = await setToken({ code, tabId, changeInfo, tab })
15021508
let verifyResults = await verify({ token, tabId, changeInfo, tab })
15031509
log('code redirect', { code, token, verify })
1504-
return
1510+
return null
15051511
}
15061512

15071513
if (tab.url.indexOf('@') === -1) {
15081514
log('no @', tab.url)
1509-
return
1515+
return null
15101516
}
15111517

15121518
log('init', tab.url)
@@ -1524,7 +1530,7 @@ export async function onUpdated (tabId, changeInfo, tab) {
15241530
timestamp,
15251531
timeBetweenUpdates
15261532
})
1527-
return
1533+
return null
15281534
}
15291535
let instance = await getInstance()
15301536
let locality = null
@@ -1592,7 +1598,7 @@ export async function onUpdated (tabId, changeInfo, tab) {
15921598
accountDropdownMatches,
15931599
locality
15941600
})
1595-
return
1601+
return null
15961602
}
15971603
}
15981604
} else {
@@ -1660,7 +1666,7 @@ export async function onUpdated (tabId, changeInfo, tab) {
16601666
accountDropdownMatches,
16611667
locality
16621668
})
1663-
return
1669+
return null
16641670
}
16651671
}
16661672

@@ -1676,7 +1682,7 @@ export async function onUpdated (tabId, changeInfo, tab) {
16761682
tabUrl: tab.url
16771683
})
16781684

1679-
return
1685+
return null
16801686
}
16811687

16821688
let lastUrlData = cache.lastUrls[cache.lastUrls.length - 1]
@@ -1694,7 +1700,7 @@ export async function onUpdated (tabId, changeInfo, tab) {
16941700
timeBetweenUpdatesForSameUrlAndIsLastUrl
16951701
})
16961702

1697-
return
1703+
return null
16981704
}
16991705
}
17001706

@@ -1716,7 +1722,7 @@ export async function onUpdated (tabId, changeInfo, tab) {
17161722
lastUrls: cache.lastUrls
17171723
})
17181724

1719-
return
1725+
return null
17201726
}
17211727
}
17221728
log('passed conditions')
@@ -1753,7 +1759,7 @@ async function syncContextMenus () {
17531759
if (await getStorageProperty('ContextMenuJump')) {
17541760
await chrome.contextMenus.create({
17551761
id: 'context',
1756-
title: 'Jump Mastodon Page 🐘 🐘 🐘 Jump Now',
1762+
title: 'Toggle Mastodon Page 🐘 🐘 🐘 Jump Now',
17571763
documentUrlPatterns: [
17581764
'*://*/@*',
17591765
'*://*/users/*',
@@ -2094,7 +2100,7 @@ export async function onMessage (message, sender, sendResponse) {
20942100
followResult,
20952101
senderUrl
20962102
})
2097-
return
2103+
return null
20982104
}
20992105
let followUrl = getUrlOrNull(followResult.url)
21002106

@@ -2306,7 +2312,7 @@ log('done')
23062312

23072313
// todo: when follow is clicked set it to pending
23082314

2309-
// todo on follow click return
2315+
// todo on follow click return null
23102316
// url of home instance profile
23112317
// not same url clicked.
23122318

@@ -2328,3 +2334,7 @@ log('done')
23282334

23292335
// TODO allow fediact reply to work
23302336
// todo confirm fediact follow no-conflict
2337+
2338+
// todo store following count in cache, if it changes, update following list
2339+
// if do this, occasionally check for new follows regardless of number of follows
2340+
// in case of unfollow + follow in quick succession equals same number of follows

app/src/content.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async function sendMessage (message, timestamp) {
7070
if (cache?.['ports']?.['onLoad']?.isDisconnected) {
7171
log('port disconnected. not sending message', message)
7272
Promise.resolve()
73-
return
73+
return null
7474
}
7575

7676
if (Array.isArray(message)) {
@@ -446,7 +446,7 @@ function onConnect (port) {
446446
message,
447447
this: this
448448
})
449-
handleMessage(message)
449+
handleMessage(message) // todo: may need to set port name
450450
})
451451
}
452452

@@ -487,12 +487,16 @@ async function onLoadHandler (input) {
487487
await sendMessage(
488488
{ type: 'onLoad' },
489489
getCallbackTimestamp('onLoad', onLoadResult)
490-
)
490+
) // something may need to ref window.location.href to ensure calllback is for the right page
491491
}
492492

493493
function onLoad () {
494494
log('onLoad', window.location.href)
495495
try {
496+
// todo resolve this
497+
// port needs to work, have a name
498+
// 'onLoad' may need to change to 'onLoad' + window.location.href
499+
// or something
496500
// chrome.runtime.connect(null, { name: 'onLoad' })
497501
chrome.runtime.sendMessage({ type: 'onLoad' })
498502
} catch (e) {

app/src/options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function removeUriHandler (url) {
111111

112112
export function cleanDomain (domain) {
113113
if (!domain) {
114-
return
114+
return null
115115
}
116116
let cleanDomain = removeUriHandler(domain)
117117

0 commit comments

Comments
 (0)