Skip to content

Commit

Permalink
修复广告拦截bug
Browse files Browse the repository at this point in the history
删除sdk多余代码
  • Loading branch information
luoxianxu committed Apr 8, 2024
1 parent 2b4851d commit 57469e4
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 27 deletions.
9 changes: 9 additions & 0 deletions libs/browser.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,18 @@ class WebView extends EventEmitter {
let jsonback = info.jsonback || {};
if (info.from == 'webdata') {
this.emit(EVENT_TYPE['WEB-MESSAGE'], jsonback)
// 监听路由
if (jsonback.action == ACTION_TYPR.historyState) {
this.emit(EVENT_TYPE['HISTORY-STATE'], jsonback.data)
}
// 新窗口打开
if(jsonback.action == ACTION_TYPR._blank){
let url = jsonback.url
if(url){
this.openNewWindow(url)
}

}
} else if (info.from == 'web') {
this.emit(EVENT_TYPE['POST-MESSAGE'], jsonback)
this.emit(EVENT_TYPE['WEB-ACTION'], jsonback)
Expand Down
6 changes: 3 additions & 3 deletions libs/src/tools/ad.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const regStr = '([0-9].\D[0-9])|(.*--.*)'
let blackUrls = uni.getStorageSync('blackUrls') || [regStr];

let blackUrls = uni.getStorageSync('blackUrls') || [];
const blackClassList = uni.getStorageSync('blackClassList') || [];
export default class AD {
constructor(wv) {
this.wv = wv;

if (!blackUrls.length) {
blackUrls = [regStr]
blackUrls = []
}
this.wv.state.setData({
blackUrls,
Expand Down
3 changes: 2 additions & 1 deletion libs/tools/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const EVENT_TYPE = {

export const ACTION_TYPR = {
'historyState':'historyState' ,//路由变化
'statistics':'statistics'
'statistics':'statistics',
'_blank':'_blank'
}

18 changes: 10 additions & 8 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name" : "Script Browser 3",
"appid" : "__UNI__A92EF1E",
"description" : "",
"versionName" : "3.0.8",
"versionCode" : 308,
"versionName" : "3.1.1",
"versionCode" : 30101,
"transformPx" : false,
/* 5+App特有相关 */
"app-plus" : {
Expand All @@ -18,7 +18,13 @@
"delay" : 0
},
/* 模块配置 */
"modules" : {},
"modules" : {
"Webview-x5" : {
"timeOut" : 30000, // 超时时间
"allowDownloadWithoutWiFi" : true // 是否允许用户在非WiFi网络时进行x5内核的下载。默认值false(如果为true,就不会显示用户确认的弹窗。)
},
"VideoPlayer" : {}
},
/* 应用发布信息 */
"distribute" : {
/* android打包配置 */
Expand All @@ -31,21 +37,17 @@
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"com.android.launcher.permission.INSTALL_SHORTCUT\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\" />",
"<uses-permission android:name=\"android.permission.MANAGE_EXTERNAL_STORAGE\" />",
" <uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\" />",
"<uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\" />",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
],
"abiFilters" : [ "arm64-v8a" ],
Expand Down
6 changes: 4 additions & 2 deletions static/html/error/error01.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@
<div class="error-content">
<p class="url"></p>
<img src="./152error40401.png" alt="" srcset="" />
<div class="title" >Loading error! reload</div>
<div class="title" >Loading error! Reload</div>
</div>
</body>
<script>
var href = '';
document.addEventListener("error", function(e){
var url = e.url; // 错误页面的url地址
document.querySelector('.url').textContent = url;
if(url.indexOf('file:')==-1){
document.querySelector('.url').textContent = url;
}
href = e.href; // 错误页面的完整路径(包括完整的协议头)
},false);
document.querySelector('.title').addEventListener('click',function(){
Expand Down
31 changes: 18 additions & 13 deletions static/sdk/web-sdk.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"use strict";

const startTime = Date.now()
globalThis.startTime = Date.now()

try {
;
(function() {

cgsdk = function() {

console.log('SDK LOADED')
window.WEB_SDK_LOADED = true;
const version = '3.0.0';
Expand Down Expand Up @@ -196,7 +195,7 @@ try {

try {
const dev = function() {
that.Data.speed = Date.now() - startTime;
that.Data.speed = Date.now() - globalThis.startTime;
let mate =
`<meta http-equiv="Content-Security-Policy" content="default-src * 'self' 'unsafe-inline' 'unsafe-eval' data: gap: content: https://xxx.com;media-src * blob: 'self' http://* 'unsafe-inline' 'unsafe-eval';style-src * 'self' 'unsafe-inline';img-src * 'self' data: content:;connect-src * blob:;">`;

Expand Down Expand Up @@ -484,11 +483,7 @@ try {
if (typeof tagname == 'undefined' || !nodelist.includes(tagname.toLocaleLowerCase())) {
return null;
}
// if (tagname.toLocaleLowerCase() == 'video') {
// node.setAttribute('controls', 'controls')
// node.setAttribute('autoplay', false);
// return _appendChild.apply(this, arguments);
// }


if (tagname.toLocaleLowerCase() == 'script') {
$websiteStatistics.addScript()
Expand All @@ -514,6 +509,16 @@ try {
}


const _open = window.open;
window.open = function(){
webSDK.sendMessage({
action: '_blank',
url: encodeURIComponent(arguments[0])
})
return {};
}


const _alert = window.alert
const _confirm = window.confirm

Expand Down Expand Up @@ -594,7 +599,7 @@ try {
// ++++++++++++++++++++++++++++++++++
// otherWebsite()

window.addEventListener('DOMContentLoaded', function() {
/* window.addEventListener('DOMContentLoaded', function() {
window.WebKitMutationObserver ||
window.MozMutationObserver;
Expand All @@ -604,13 +609,13 @@ try {
let observer = new MutationObserver(function(records) {
// otherWebsite()
});
let body = document.querySelector('body')
let body = document.body || document.querySelector('body')
observer.observe(body, {
'childList': true,
'subtree': true
})
}
})
}) */

// +++++++++++++++++++++++++++++++++++++

Expand Down

0 comments on commit 57469e4

Please sign in to comment.