//修正按钮元素 function toerji(item,info) { info = info || storage0.getMyVar('一级源接口信息'); let extra = item.extra || {}; extra.name = extra.name || extra.pageTitle || (item.title?item.title.replace(/‘|’|“|”|<[^>]+>/g,""):""); extra.img = extra.img || item.pic_url || item.img; extra.stype = info.type; extra.pageTitle = extra.pageTitle || extra.name; if(item.url && !/js:|select:|\(|\)|=>|@|toast:/.test(item.url)){ extra.surl = item.url.replace(/hiker:\/\/empty|#immersiveTheme#|#autoCache#|#noRecordHistory#|#noHistory#|#noLoading#|#/g,""); extra.sname = info.name; } if((item.col_type!="scroll_button") || item.extra){ item.extra = extra; } item.url = (extra.surl||!item.url)?$('hiker://empty#immersiveTheme##autoCache#').rule(() => { require(config.依赖); erji(); }):item.url return item; } //简繁互转,x可不传,默认转成简体,传2则是转成繁体 function jianfan(str,x) { require(config.依赖.match(/http(s)?:\/\/.*\//)[0] + 'SrcSimple.js'); return PYStr(str,x); } //写接口数据临时缓存 function cacheData(jkdata){ let fileid = jkdata.type + '_'+ jkdata.name; let cachefile = `hiker://files/_cache/${fileid}.json`; if (!fileExist(cachefile)) { writeFile(cachefile,JSON.stringify(jkdata)); } } //来自阿尔法大佬的主页幻灯片 function banner(start, arr, data, cfg){ let id = 'juyue'; let rnum = Math.floor(Math.random() * data.length); let item = data[rnum]; putMyVar('rnum', rnum); let time = 5000; let col_type='pic_1_card'; let desc=''; if (cfg != undefined) { time = cfg.time ? cfg.time : time; col_type=cfg.col_type?cfg.col_type:col_type; desc=cfg.desc?cfg.desc:desc; } arr.push({ col_type: col_type, img: item.img, desc:desc, title: item.title, url: item.url, extra: { id: 'bar', } }) if (start == false || getMyVar('benstart', 'true') == 'false') { unRegisterTask(id) return } let obj = { data: data, method: config.依赖.match(/http(s)?:\/\/.*\//)[0] + 'SrcJuMethod.js', info: storage0.getMyVar('一级源接口信息') }; registerTask(id, time, $.toString((obj) => { var data = obj.data; var rum = getMyVar('rnum'); var i = Number(getMyVar('banneri', '0')); if (rum != '') { i = Number(rum) + 1 clearMyVar('rnum') } else { i = i + 1; } if (i > data.length - 1) { i = 0 } var item = data[i]; try { require(obj.method); updateItem('bar', toerji(item,obj.info)); } catch (e) { log(e.message) unRegisterTask('juyue') } putMyVar('banneri', i); }, obj)) } //图片压缩 function imageCompress(imgurl,fileid) { function compress(path, topath) { if (!path) { return imgurl; } let obj = Object.assign({},path); let tmpfile = "hiker://files/_cache/1.txt"; if (!fileExist(tmpfile)) { writeFile(tmpfile, ''); } const Bitmap = android.graphics.Bitmap; const BitmapFactory = android.graphics.BitmapFactory; const FileOutputStream = java.io.FileOutputStream; let options1 = new BitmapFactory.Options(); options1.inJustDecodeBounds = true; options1.inPurgeable = true; let bitmap1; if (typeof path === "object" && path.getClass) { bitmap1 = BitmapFactory.decodeStream(path, null, options1); } else { bitmap1 = BitmapFactory.decodeFile(path, options1); } options1.inJustDecodeBounds = false; let size; if(options1.outWidth>=options1.outHeight){ size = options1.outWidth; }else{ size = options1.outHeight; } if(size>720){ let options2 = new BitmapFactory.Options(); options2.inSampleSize = parseInt(size/720) || 2; options2.inPurgeable = true; let bitmap2; if (topath && typeof obj === "object" && obj.getClass) { bitmap2 = BitmapFactory.decodeStream(obj, null, options2); closeMe(obj); } else { bitmap2 = BitmapFactory.decodeFile(obj, options2); topath = topath || obj; } let os = new FileOutputStream(topath); try { bitmap2.compress(Bitmap.CompressFormat.PNG, 100, os); return "file://" + topath; } catch (e) { log(e.toString()); } os.flush(); os.close(); } return imgurl; } function getName(path) { const File = java.io.File; return new File(path).getName() + ""; } let f = fetch(imgurl, { inputStream: true }); let newpath = "/storage/emulated/0/Android/data/com.example.hikerview/files/Documents/_cache/"+(fileid||"")+"_"+getName(imgurl); return compress(f, newpath); }