Skip to content

Commit

Permalink
adjust lots type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsVipra authored and nachtjasmin committed Aug 1, 2023
1 parent cc6d473 commit 2c6c39e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/content_scripts/protoots.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ async function addProplate(element) {

/**
* Generates a proplate and adds it as a sibling of the given nameTagEl
* @param {string} statusId Id of the target object
* @param {string} accountName Name of the account the plate is for
* @param {HTMLElement} nametagEl Element to add the proplate next to
* @param {string|undefined} statusId Id of the target object
* @param {string|null} accountName Name of the account the plate is for
* @param {HTMLElement|null} nametagEl Element to add the proplate next to
* @param {string} type type of the target object
* @returns
*/
Expand Down Expand Up @@ -234,7 +234,7 @@ async function addProplate(element) {
/**
* Gets the data-id from the given element
* @param {HTMLElement} element Element with data-id attribute
* @returns {string}
* @returns {string|undefined}
*/
function getID(element) {
let id = element.dataset.id;
Expand Down Expand Up @@ -270,19 +270,20 @@ async function addProplate(element) {

/**
* Gets the given element's textcontent or given attribute
* @param {HTMLElement} element Element which textcontent is the account name
* @param {HTMLElement|null} element Element which textcontent is the account name
* @param {string} attribute Attribute from which to pull the account name
* @returns {string|null} Normalised account name or null if it can't be found.
*/
function getAccountName(element, attribute = "textContent") {
if (!element) return null;
let accountName = element.textContent;
if (attribute != "textContent") {
accountName = element.getAttribute(attribute);
}

if (!accountName) {
warn(
"Could not extract the account name from the element, aborting pronoun extraction:",
`Could not extract the account name from the element, using attribute ${attribute} aborting pronoun extraction:`,
element,
);
return null;
Expand Down
3 changes: 2 additions & 1 deletion src/libs/protootshelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ export function normaliseAccountName(name) {
* Turns a link to an account on a remote instance into a username.
*
* e.g. `https://example.com/@test` -> `@[email protected]`
* @param {string} url URL to an account on their own instance
* @param {string|null} url URL to an account on their own instance
* @returns {string} username (not normalised)
*/
export function accountNameFromURL(url) {
if (!url) return null;
const splitURL = url.split("/");

const username = [splitURL.pop(), splitURL.pop()].join("@");
Expand Down

0 comments on commit 2c6c39e

Please sign in to comment.