Skip to content

Commit

Permalink
v1.11.0 / 2021-08-20
Browse files Browse the repository at this point in the history
 * Include text extracted from post bodies so they can be filtered even if they've been heavily styled
  • Loading branch information
bjornstar committed Aug 20, 2021
1 parent 864b229 commit ea4787c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Tumblr Savior Changelog

## v1.11.0 / 2021-08-20
* Include text extracted from post bodies so they can be filtered even if they've been heavily styled

## v1.10.0 / 2021-08-18
* Update CSS_CLASS_MAP -- https://assets.tumblr.com/pop/cssmap-6fca4540.json (Fixes #78)
* Use textContent instead of innerText for better performance
* Use `textContent` instead of `innerText` for better performance
* [`package.json`] Update devDependency `eslint` from `v7.10.0` to `v7.32.0`
* [`CHANGELOG.md`] Use slashes to separate the version number from the year
* [`CHANGELOG.md`] Use a slash to separate the version number from the year
* [`LICENSE`] Update most recent year to `2021`

## v1.9.0 / 2021-04-20
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tumblr-savior",
"version": "1.10.0",
"version": "1.11.0",
"description": "Would you like to control what shows up on your dashboard? Tumblr Savior is here to save you!",
"scripts": {
"test": "eslint src"
Expand Down
2 changes: 1 addition & 1 deletion src/data/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ const defaultSettings = {
'show_notice': true,
'show_tags': true,
'show_words': true,
'version': '1.10.0'
'version': '1.11.0'
}; // Initialize default values.
13 changes: 7 additions & 6 deletions src/data/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,12 @@ function hide_tags() {

const hideNoticesStyle = [ `article.tumblr-savior-blacklisted:not(.tumblr-savior-override) {display:none;}` ];

function extractText(node) {
function extractText({ childNodes, nodeType, tagName, textContent }, isChildOfP) {
// We were doing a naive tag removal and that worked until tumblr sometimes
// didn't escape html in blog descriptions. So now we do it explicitly (#54)
if (node.nodeType === 3) return node.textContent;
if (nodeType === 3) return textContent + (isChildOfP ? '' : ' ');

return Array.prototype.map.call(node.childNodes, extractText).join(' ');
return Array.prototype.filter.call(childNodes, ({ textContent }) => textContent).map(child => extractText(child, isChildOfP || tagName === 'P')).join('');
}

function toggleStyle(id) {
Expand Down Expand Up @@ -513,15 +513,16 @@ function checkPost(post) {

let hasFilteredContent = false;

postText += Array.prototype.reduce.call(post.childNodes, (out, { classList, innerHTML, tagName }) => {
postText += Array.prototype.reduce.call(post.childNodes, (out, node) => {
const { classList, innerHTML, tagName } = node;
hasFilteredContent = hasFilteredContent || classList.contains(CSS_CLASS_MAP.filteredScreen);

if (settings.ignore_body || ['HEADER', 'TS-NOTICE'].includes(tagName) || classList.contains(CSS_CLASS_MAP.footerWrapper) || (settings.ignore_filtered_content && hasFilteredContent)) {
return out;
}

return out + innerHTML;
}, '');
return `${out} ${innerHTML} ${extractText(node)} `;
}, ' ');

const isRecommendedPost = post.querySelector(css('recommendationReasonTopTeaserWrapper'));

Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Tumblr Savior",
"version": "1.10.0",
"version": "1.11.0",
"description": "Would you like to control what shows up on your dashboard? Tumblr Savior is here to save you!",
"background": {
"scripts": [ "data/defaults.js", "lib/main.js" ]
Expand Down

0 comments on commit ea4787c

Please sign in to comment.