diff --git a/app/src/main/assets/ClipboardGuard.js b/app/src/main/assets/ClipboardGuard.js new file mode 100644 index 00000000..152f1869 --- /dev/null +++ b/app/src/main/assets/ClipboardGuard.js @@ -0,0 +1,5 @@ +/** + * @name: ClipboardGuard + * @author: huanchengfly + **/ +"use strict";function _toConsumableArray(e){if(Array.isArray(e)){for(var n=0,r=Array(e.length);n=threshold||confirm("ClipboardGuardCopyRequest")||(e.preventDefault(),e.stopPropagation())}var threshold=7,key=encodeURIComponent("ClipboardGuardRunning");!function(){if(!window[key])try{window[key]=!0,[document].concat(_toConsumableArray(Array.from(document.getElementsByTagName("iframe")).map(function(e){return e.contentDocument}))).forEach(function(e){e.addEventListener("copy",eventHandler,{passive:!1,capture:!0})})}catch(e){console.log("ClipboardGuard: "+e)}}(); \ No newline at end of file diff --git a/app/src/main/java/com/huanchengfly/tieba/post/components/dialogs/PermissionDialog.java b/app/src/main/java/com/huanchengfly/tieba/post/components/dialogs/PermissionDialog.java index 5a5e8105..9a7c7093 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/components/dialogs/PermissionDialog.java +++ b/app/src/main/java/com/huanchengfly/tieba/post/components/dialogs/PermissionDialog.java @@ -132,5 +132,6 @@ public class PermissionDialog extends AlertDialog implements View.OnClickListene public static class CustomPermission { public static final int PERMISSION_LOCATION = 0; public static final int PERMISSION_START_APP = 1; + public static final int PERMISSION_CLIPBOARD_COPY = 2; } } \ No newline at end of file diff --git a/app/src/main/java/com/huanchengfly/tieba/post/fragments/WebViewFragment.java b/app/src/main/java/com/huanchengfly/tieba/post/fragments/WebViewFragment.java index af5209b3..888c2671 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/fragments/WebViewFragment.java +++ b/app/src/main/java/com/huanchengfly/tieba/post/fragments/WebViewFragment.java @@ -70,6 +70,7 @@ public class WebViewFragment extends BaseFragment implements DownloadListener { private String tbliteJs; private String nightJs; private String aNightJs; + private String clipboardGuardJs; private WebView mWebView; private NavigationHelper navigationHelper; private ValueCallback uploadMessage; @@ -190,6 +191,7 @@ public class WebViewFragment extends BaseFragment implements DownloadListener { tbliteJs = AssetUtil.getStringFromAsset(getAttachContext(), "tblite.js"); nightJs = AssetUtil.getStringFromAsset(getAttachContext(), "night.js"); aNightJs = AssetUtil.getStringFromAsset(getAttachContext(), "anight.js"); + clipboardGuardJs = AssetUtil.getStringFromAsset(getAttachContext(), "ClipboardGuard.js"); } @Override @@ -264,6 +266,7 @@ public class WebViewFragment extends BaseFragment implements DownloadListener { private void injectJavaScript() { if (mWebView == null) return; + mWebView.evaluateJavascript(clipboardGuardJs, null); String nowTheme = ThemeUtil.getTheme(getAttachContext()); String url = mWebView.getUrl(); if (url == null || nowTheme == null) { @@ -415,12 +418,27 @@ public class WebViewFragment extends BaseFragment implements DownloadListener { } public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) { - DialogUtil.build(view.getContext()) - .setTitle("Confirm") - .setMessage(message) - .setPositiveButton(android.R.string.ok, (dialog, which) -> result.confirm()) - .setNegativeButton(android.R.string.cancel, (dialog, which) -> result.cancel()) - .create().show(); + if ("ClipboardGuardCopyRequest".equalsIgnoreCase(message)) { + Uri uri = Uri.parse(mWebView.getUrl()); + if (uri != null && uri.getHost() != null) { + new PermissionDialog(getAttachContext(), + new PermissionBean(PermissionDialog.CustomPermission.PERMISSION_CLIPBOARD_COPY, + uri.getHost(), + getAttachContext().getString(R.string.title_ask_permission_clipboard_copy, uri.getHost()), + R.drawable.ic_round_file_copy)) + .setOnGrantedCallback(isForever -> result.confirm()) + .setOnDeniedCallback(isForever -> result.cancel()) + .show(); + } + } else { + DialogUtil.build(view.getContext()) + .setTitle("Confirm") + .setMessage(message) + .setPositiveButton(android.R.string.ok, (dialog, which) -> result.confirm()) + .setNegativeButton(android.R.string.cancel, (dialog, which) -> result.cancel()) + .create() + .show(); + } return true; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ef5c0b9a..10c30b45 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -209,6 +209,7 @@ 禁止 不再询问 要允许 %1$s 访问您的%2$s吗? + 要允许 %1$s 写入您的剪贴板吗? 要允许 %1$s 打开您的%2$s吗? 应用 状态栏遮罩 @@ -399,4 +400,11 @@ 签到失败 请先登录 正在检查更新 + 建议您使用其他途径发贴 + 继续使用本软件发贴可能会出现发贴失败、发贴被隐藏甚至封号等异常情况,建议您使用官方客户端或 PC 网页版发贴 + 使用官方客户端发贴 + 启动失败 + 使用 PC 网页版发贴 + 继续使用本软件发贴 + 写入剪贴板