<commit_before>/*
 * Copyright (c) 2022 toastkidjp.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompany this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html.
 */

package jp.toastkid.yobidashi.browser.webview.usecase

import android.os.Build
import android.webkit.WebView
import jp.toastkid.lib.preference.PreferenceApplier

class DarkCssInjectorUseCase {

    operator fun invoke(webView: WebView) {
        webView.evaluateJavascript(CSS_INJECTOR_SCRIPT) { }
    }

    companion object {
        private const val CSS_INJECTOR_SCRIPT = """
                    (function () {
                        'use strict';
                        
                        var headElement = document.getElementsByTagName('head')[0],
                            styleElement = document.createElement('style');
                        
                        styleElement.type = 'text/css';
                        
                        var cssText = 
                            'html{      filter: invert(1) hue-rotate(180deg);  }'
                               + 'html img, .Image, .ytp-cued-thumbnail-overlay-image, .EmbeddedImage,'
                               + '.theme-Kisekae__backgroundImage--headerChar {'
                               +      'filter: invert(1) hue-rotate(180deg);'
                               + '}';
                        
                        if (styleElement.styleSheet) {
                            styleElement.styleSheet.cssText = cssText;
                        } else {
                            styleElement.appendChild(document.createTextNode(cssText));
                        }

                        headElement.appendChild(styleElement);
                    }());
                """

        fun isTarget(preferenceApplier: PreferenceApplier) =
            preferenceApplier.useDarkMode() && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q

    }
}<commit_msg>refactor #523 Enable to accept null.<commit_after>/*
 * Copyright (c) 2022 toastkidjp.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompany this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html.
 */

package jp.toastkid.yobidashi.browser.webview.usecase

import android.os.Build
import android.webkit.WebView
import jp.toastkid.lib.preference.PreferenceApplier

class DarkCssInjectorUseCase {

    operator fun invoke(webView: WebView?) {
        webView?.evaluateJavascript(CSS_INJECTOR_SCRIPT) { }
    }

    companion object {
        private const val CSS_INJECTOR_SCRIPT = """
                    (function () {
                        'use strict';
                        
                        var headElement = document.getElementsByTagName('head')[0],
                            styleElement = document.createElement('style');
                        
                        styleElement.type = 'text/css';
                        
                        var cssText = 
                            'html{      filter: invert(1) hue-rotate(180deg);  }'
                               + 'html img, .Image, .ytp-cued-thumbnail-overlay-image, .EmbeddedImage,'
                               + '.theme-Kisekae__backgroundImage--headerChar {'
                               +      'filter: invert(1) hue-rotate(180deg);'
                               + '}';
                        
                        if (styleElement.styleSheet) {
                            styleElement.styleSheet.cssText = cssText;
                        } else {
                            styleElement.appendChild(document.createTextNode(cssText));
                        }

                        headElement.appendChild(styleElement);
                    }());
                """

        fun isTarget(preferenceApplier: PreferenceApplier) =
            preferenceApplier.useDarkMode() && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q

    }
}
{'fraction_non_alphanumeric': 0.08770668583752696, 'fraction_numerical': 0.008866522885214475, 'mean_word_length': 1.4338192419825073, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2409502', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1000, 'n_words': 199}