Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update core.js stop injecting junk into HTML element on load #2197

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 106 additions & 5 deletions js&css/extension/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,103 @@ var extension = {
}
};

// list of settings we inject into HTML element as attributes, used by CSS.
let htmlAttributes = [
"activated",
"ads",
"always_show_progress_bar",
"bluelight",
"channel_compact_theme",
"channel_hide_featured_content",
"collapse_of_subscription_sections",
"columns",
"comments",
"comments_sidebar",
"comments_sidebar_left",
"comments_sidebar_simple",
"compactSpacing",
"description",
"embeddedHidePauseOverlay",
"embeddedHideShare",
"embeddedHideYoutubeLogo",
"header_hide_country_code",
"header_hide_right_buttons",
"header_improve_logo",
"header_position",
"header_transparent",
"hide_animated_thumbnails",
"hide_author_avatars",
"hide_clip_button",
"hide_comments_count",
"hide_date",
"hide_details",
"hide_dislike_button",
"hide_download_button",
"hide_footer",
"hide_gradient_bottom",
"hide_more_button",
"hide_playlist",
"hide_report_button",
"hide_save_button",
"hide_scroll_for_details",
"hide_share_button",
"hide_shorts_remixing",
"hide_sidebar",
"hide_thanks_button",
"hide_thumbnail_overlay",
"hide_video_title_fullScreen",
"hide_views_count",
"hide_voice_search_button",
"improvedtube_search",
"likes",
"livechat",
"mini_player_cursor",
"no_page_margin",
"player_autoplay_button",
"player_color",
"player_crop_chapter_titles",
"player_fit_to_win_button",
"player_hide_annotations",
"player_hide_cards",
"player_hide_endscreen",
"player_hide_skip_overlay",
"player_miniplayer_button",
"player_next_button",
"player_play_button",
"player_previous_button",
"player_remote_button",
"player_screen_button",
"player_settings_button",
"player_show_cards_on_mouse_hover",
"player_size",
"player_size",
"player_subtitles_button",
"player_transparent_background",
"player_view_button",
"player_volume_button",
"red_dislike_button",
"related_videos",
"remove_black_bars",
"remove_history_shorts",
"remove_home_page_shorts",
"remove_related_search_results",
"remove_shorts_reel_search_results",
"remove_subscriptions_shorts",
"remove_trending_shorts",
"schedule",
"scroll_bar",
"scroll_to_top",
"search_focus",
"sidebar_left",
"squared_user_images",
"subscribe",
"theme",
"thumbnails_hide",
"thumbnails_right",
"transcript",
"youtube_home_page",
"youtubeDetailButtons"
];

/*--------------------------------------------------------------
# CAMELIZE
Expand Down Expand Up @@ -117,7 +214,7 @@ extension.events.trigger = async function (type, data) {
/*--------------------------------------------------------------
# INJECT
----------------------------------------------------------------

--------------------------------------------------------------*/

extension.inject = function (paths, callback) {
Expand Down Expand Up @@ -270,13 +367,15 @@ extension.storage.get = function (key) {

extension.storage.listener = function () {
chrome.storage.onChanged.addListener(function (changes) {
for (var key in changes) {
var value = changes[key].newValue,
for (const key in changes) {
let value = changes[key].newValue,
camelized_key = extension.camelize(key);

extension.storage.data[key] = value;

document.documentElement.setAttribute('it-' + key.replace(/_/g, '-'), value);
if (htmlAttributes.includes(key)) {
document.documentElement.setAttribute('it-' + key.replace(/_/g, '-'), value);
}

if (typeof extension.features[camelized_key] === 'function') {
extension.features[camelized_key](true);
Expand Down Expand Up @@ -312,7 +411,9 @@ extension.storage.load = function (callback) {
}

for (const key in items) {
document.documentElement.setAttribute('it-' + key.replace(/_/g, '-'), items[key]);
if (htmlAttributes.includes(key)) {
document.documentElement.setAttribute('it-' + key.replace(/_/g, '-'), items[key]);
}
}

extension.events.trigger('storage-loaded');
Expand Down