User:Gary/comments in local time.js: Difference between revisions

Content deleted Content added
bug fixes
fixes
 
Line 10:
*/
$(() => {
const nowrapStyle = `style="white-space: nowrap;"`;
 
/**
* Given a number, add a leading zero if necessary, so that the final number
Line 139 ⟶ 137:
utcValue >= 0 ? `+${utcValue}` : `−${Math.abs(utcValue.toFixed(1))}`;
 
const timePartutcPart = `<span class="localcomments-time" ${nowrapStyle}>(UTC${finalTimeutcOffset}</span>)`;
const datePart = `<span class="localcomments-date">${date}</span>`;
const utcPart = `<span class="localcomments-utc" ${nowrapStyle}>(UTC${utcOffset})</span>`;
 
const returnDate = this.LocalComments.timeFirst
? `${timePartfinalTime}, ${datePartdate} ${utcPart}`
: `${datePartdate}, ${timePartfinalTime} ${utcPart}`;
 
return { returnDate, time };
}
 
Line 212 ⟶ 208:
: '';
 
return `<span ${nowrapStyle}>${formattedDate}</span><span ${nowrapStyle}>${formattedDayOfTheWeek}</span><span ${nowrapStyle}>${descriptiveDifference}</span>`;
}
 
Line 437 ⟶ 433:
const beforeMatch = value.slice(0, position);
const afterMatch = value.slice(position + stringLength);
const { returnDate, time } = this.adjustTime(match.toString(), search);
match.toString(),
search
);
const timestamp = time ? time.getTime() : '';
 
// IsCreate the "timestamp"code attributeto useddisplay forthe new local comments microformats?content.
const $span = $(
`<span class="localcomments" style="font-size: 95%;" timestamp="${timestamp}" title="${match}">${returnDate}</span>`
);
 
// Replace the existing text node in the page with our new local
// comments node.
$(node).replaceWith($span);
 
const// Replace the text content that appears $before =the $(timestamp.
if (beforeMatch) {
`<span class="before-localcomments">${beforeMatch}</span>`
); $span.before(
const utcPart = `<span class="localcommentsbefore-utclocalcomments" ${nowrapStyle}>(UTC${utcOffsetbeforeMatch})</span>`;
 
const $after = $();
);}
`<span class="after-localcomments">${afterMatch}</span>`
);
 
// Replace the text content that appears after the timestamp.
$span.before($before);
$span.afterif ($afterafterMatch); {
match$span.toStringafter(),
const datePart = `<span class="localcommentsafter-datelocalcomments">${dateafterMatch}</span>`;
search);
);}
}
} else {