Description

AutoBlocker is a content script responsible for discovering Twitter handles and checking them for banned keywords. It works as follows:

It runs in the browser tab context and watches DOM changes. It then attempts to find twitter handles in the DOM tree when the tree changes.

After finding handles, those handles are first placed in a temporary queue to limit API calls. Once the queue is "full enough" and API credentials are available, the discovered handles will be checked.

First it will request the bio for each handle and then check that bio for prohibited keywords. If keyword is detected, either prompt user to confirm the blocking (user preference) or automatically block. Manually choosing not to block will add the handle to a whitelist.

Notes:

  • The queue stage is used to limit number of API calls, and is necessary to avoid exceeding Twitter rate limit
  • Handle is only checked once per session; checked handled are kept in memory and will not be checked again until full page reload occurs.
  • Content script is specific to a single tab; if user is browsing twitter in multiple tabs, each tab maintains its own state.

Methods


<static> registerListener()

Description

Add message listener to know when to reload settings.


<static> loadSettings( callback )

Description

Load user settings from storage.

Parameters
Name Type Attributes Description
callback function <nullable>

<static> obtainTokens( callback )

Description

Request the tokens from background context.

Parameters
Name Type Attributes Description
callback function <nullable>

will call iff ready to proceed


<static> startWatch()

Description

Initiate watch for DOM tree changes


<static> onDomChange( mutationsList )

Description

Handle DOM tree changes

Parameters
Name Type Description
mutationsList

<static> lookForDouches()

Description

Start douchy user lookup flow.


<static> findHandles()

Description

Look for handles in the timeline


Description

Check DOM links and queue newly discovered handles.

Parameters
Name Type Description
link Element

DOM node


Description

Determine if some link element is a handle.

Parameters
Name Type Description
link Element

DOM element

Returns

<static> parseHandle( link )

Description

Extract handle string from a DOM element.

Parameters
Name Type Description
link Element

element

Returns

twitter user handle


<static> requestBios()

Description

If there are enough names are in queue, request bios from API.


<static> processBios( users )

Description

Check users to find bios matching blocking criteria.

Parameters
Name Type Description
users Array.<Object>

<static> isBlockMatch( user )

Description

Check if user should be blocked. If yes, user will contain a truthy match property indicating a keyword was matched.

Parameters
Name Type Description
user Object
Returns

true if blockable


<static> checkWords( words, user )

Description

Match bio against keywords. Here we record the matched keyword to be able to log it.

Parameters
Name Type Description
words Array.<String>

keywords to check

user Object

user object

Returns

true for a douche


<static> limitAlertCount( users )

Description

This method ensures the number of alerts shown to user does not exceed a configurable upper limit. If input exceeds the limit, excess items will be re-queued. Method will return at most max allowed matches.

Parameters
Name Type Description
users Array.<Object>
Returns

limited count of users


<static> sequentiallyBlock( users )

Description

Recursively block a list of users

Parameters
Name Type Description
users Array.<Object>

<static> buildAlert( bio, name )

Description

Construct a window alert

Parameters
Name Type Description
bio string

user's bio text

name string

user's display name

Returns

alert text


<static> executeBlock( user )

Description

Block a user

Parameters
Name Type Description
user Object

twitter user object

Name Type Description
bio string

bio text

id string

twitter id

handle string

handle

name string

display name

match string

matched keyword

img string

profile image

Returns