博採眾長 app

警告
本文最后更新于 2023-11-17,文中内容可能已过时。

0.1 介绍

使用 fusion app 对网页进行的封装。
功能:

  • 浏览本博客,主页
  • 私人网盘
  • 2048 等小游戏
  • 在线客服,QQ 等
  • pc 与移动浏览器标识切换
  • 留言,打赏,博主日志等
  • 分享功能,分享到 QQ,微信,浏览器打开等
  • app 内添加书签,自动记录历史记录,刷新等
  • 配合博客的PWA + quicklink功能可实现离线浏览

0.2 下载

app 内也可以更新,不过就我自己用,懒得更新。

PWA 应用

  1. 地址栏输入:Chrome://flags
  2. 搜索并启用以下项目:Desktop PWAs(桌面 PWAs)、App Banners(应用横幅)、Experimental App Banners(实验性应用横幅)
  3. 重启浏览器使修改的设置生效
  4. 点击地址栏最右边按钮
  5. 安装“博採眾長”

0.3 部分源码

看到这些中文的函数总觉得怪怪的哈哈哈 😂 语言:lua

0.3.1 检测更新

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
--检查测当前是否最新版本
local dl=ProgressDialog.show(activity,nil,'更新检测中…')
dl.show()
local tt=Ticker()
tt.start()
packinfo=this.getPackageManager().getPackageInfo(this.getPackageName(),((32552732/2/2-8183)/10000-6-231)/9)
version=tostring(packinfo.versionName)
versioncode=tostring(packinfo.versionCode)

url="https://share.weiyun.com/43fa66d8fc95db27141530ed2d006be2";
function 过滤 (content)
  版本名=content:match("【版本名】(.-)【版本名】")
  版本=content:match("【版本】(.-)【版本】")
  内容=content:match("【内容】(.-)【内容】")
  链接=content:match("【链接】(.-)【链接】")
if(版本名==nil) then
  版本名="获取失败"
end
if(版本==nil) then
  版本="0"
end
if(内容==nil) then
  内容="获取失败"
end
if(链接==nil) then
  弹出消息 ("服务器参数配置错误,请过段时间再次尝试")
end

if(版本 > versioncode) then
  dl.dismiss()
    tt.stop()
对话框 ()
. 设置标题 ("检测到更新")
. 设置消息 ("版本:"..version.."→".. 版本名。."\n 更新内容:".. 内容)
. 设置积极按钮 ("下载更新",function()
  下载文件(链接)
  弹出消息 ("下载更新中…")
end)
. 设置消极按钮 ("取消更新")
. 显示 ()
else
dl.dismiss()
    tt.stop()
弹出消息 ("当前已是最新版本!")
end
Http.get(url,nil,"UTF-8",nil,function(code,content,cookie,header)
  if(code==200 and content)then
    content=content:match("\"html_content\":(.-),"):gsub("\\u003C/?.-%>",""):gsub("\\\\","&revs;"):gsub("\\n","\n"):gsub("&nbsp;"," "):gsub("&lt;","<"):gsub("&gt;",">"):gsub("&quot;","\""):gsub("&apos;","'"):gsub("&revs;","\\"):gsub("&amp;","&");
    过滤 (content)
  else
  dl.dismiss()
    tt.stop()
     弹出消息 ("本地网络或服务器异常 "..code)
  end
end)

0.3.2 方向锁定

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
--flag 在程序启动事件声明的全局变量
if flag==1 then
  activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
  SetHSP="H"
else
  SetHSP=nil
end

if SetHSP==nil then
  --竖屏锁定
  activity.setRequestedOrientation(1);
  flag=1
else
  flag=0
end

0.3.3 程序启动事件

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
弹出消息 ("©2018 李瑞豪")

--自动,由物理感应器决定
import "android.content.pm.ActivityInfo"
flag=1

--程序退出时执行对话框
function onKeyDown(key,event)
  if(key==4)then
    if(webView.canGoBack())then
      webView.goBack()
    else
      appinfo=this.getPackageManager().getApplicationInfo(this.getPackageName(),0)
      applabel=this.getPackageManager().getApplicationLabel(appinfo)
      退出确认=对话框 ()
      . 设置消息 ("您确定要退出 "..applabel.." 吗?")
      退出按钮={
        [1]=function()
          退出确认
          . 设置积极按钮 ("确认",function()
            退出程序 ()
            end
             )
             . 设置中立按钮 ("清除缓存",function()
               对话框 ()
               . 设置消息 ("清除缓存后再次运行程序将变得缓慢、n 您确定要清除 "..applabel.." 的缓存吗?")
               . 设置积极按钮 ("确定",function()
                os.execute("pm clear "..this.packageName)
                退出程序 ()
                end)
               . 设置消极按钮 ("取消",function()
                end)
              . 显示 ()
             end
           )
          . 设置消极按钮 ("取消")
          end
        }
      math.randomseed(tonumber(tostring(os.time()):reverse():sub(1, 6)))
      退出按钮 [math.random(1,1)]()
      退出确认。show()
    end
    return true
  end
end

--历史记录
lstads="/data/data/"..activity.getPackageName().."/lst.lua"
lstwebads="/data/data/"..activity.getPackageName().."/lstweb.lua"
--2. 序列化
function slz(obj)
  local lua = ""
  local t = type(obj)
  if t == "number" then
    lua = lua .. obj
  elseif t == "boolean" then
    lua = lua .. tostring(obj)
  elseif t == "string" then
    lua = lua .. string.format("%q", obj)
  elseif t == "table" then
    lua = lua .. "{\n"
    for k, v in pairs(obj) do
      lua = lua .. "[" .. slz(k) .. "]=" .. slz(v) .. ",\n"
    end
    local metatable = getmetatable(obj)
    if metatable ~= nil and type(metatable.__index) == "table" then
      for k, v in pairs(metatable.__index) do
        lua = lua .. "[" .. slz(k) .. "]=" .. slz(v) .. ",\n"
      end
    end
    lua = lua .. "}"
  elseif t == "nil" then
    return nil
  else
    error("can not serialize a " .. t .. " type.")
  end
  return lua
end
function rslz(lua)
  local t = type(lua)
  if t == "nil" or lua == "" then
    return {}
  elseif t == "number" or t == "string" or t == "boolean" then
    lua = tostring(lua)
  else
    error("can not unserialize a " .. t .. " type.")
  end
  lua = "return " .. lua
  local func = loadstring(lua)
  if func == nil then
    return nil
  end
  return func()
end

--3. 历史记录框布局
function hstshow()
  hstlayout={
    LinearLayout,
    orientation="1",
    gravity="center",
    layout_width="wrap_content",
    layout_height="wrap_content",
    {
      TextView,
      text="",
      gravity="center",
      layout_width="wrap_content",
      textSize="0sp",
      background="#000000",
      layout_height="15dp",},
    {
      TextView,
      text="历史记录",
      gravity="center",
      layout_width="wrap_content",
      textSize="30sp",
      textStyle="bold",
      layout_height="50dp",},
    {
      ListView,
      id="hlst",
      items=lst,
      layout_width="fill",
      layout_height="wrap_content",
    },
  }
end

--##功能函数##

--1. 读取历史文件
function read_hst()
  import "java.io.File"
  File(lstads).createNewFile()
  slst=io.open(lstads):read("*a")
  File(lstwebads).createNewFile()
  slstweb=io.open(lstwebads):read("*a")
  --转换成 table
  lst=rslz(slst)
  lstweb=rslz(slstweb)
end

--2. 新网页加入历史记录
function add_hst()
  if string.len(webView.getTitle())<=300 then--粗略过掉无效标题
    newtitle=webView.getTitle()
    newurl=webView.getUrl()
    table.insert(lst,1,newtitle) --标题表添加新标题
    table.insert(lstweb,1,newurl) --网址表添加新网址
  end
end

--3. 存储历史文件
function save_hst()
  --转换成 string
  slst=slz(lst)
  slstweb=slz(lstweb)
  --保存
  file=io.open(lstads,"w+")
  io.output(file)
  io.write(slst)
  io.flush()
  io.close(file)
  file=io.open(lstwebads,"w+")
  io.output(file)
  io.write(slstweb)
  io.flush()
  io.close(file)
end

--4. 显示历史记录框
function show_hst()
  hstshow()
  local hl=AlertDialog.Builder(activity)
  .setView(loadlayout(hstlayout))
  .setNegativeButton("取消",DialogInterface.OnClickListener{
    onClick=function()
    end
  })
  .create()
  hl.show()
  hlst.onItemClick=function(l,v,c,b)
    加载网页 (lstweb[b])
    hl.dismiss()
  end
  hlst.onItemLongClick=function(l,v,c,b)
    hl.dismiss()
    对话框 ()
    . 设置消息 ("是否删除记录?")
    . 设置消极按钮 ("取消",function()
      show_hst()
    end)
    . 设置积极按钮 ("确定",function()
      table.remove(lst,b)
      table.remove(lstweb,b)
      save_hst()
      show_hst()
    end )
    . 显示 ()
    return true
  end
end
--5. 清除缓存
function clr()
  --导入 File 类
  import "java.io.File"
  --显示多选框
  items={"浏览记录","缓存文件"}
  多选对话框=AlertDialog.Builder(this)
  .setTitle("清除记录")
  --勾选后执行
  .setPositiveButton("确定",function()
    if clearhistory==1 and clearall==1 then
      File(lstads).delete()
      File(lstwebads).delete()
      lst={}
      lstweb={}
      os.execute("pm clear "..activity.getPackageName())
    elseif clearhistory==0 and clearall==1 then
      os.execute("pm clear "..activity.getPackageName())
    elseif clearhistory==1 and clearall==0 then
      File(lstads).delete()
      File(lstwebads).delete()
      lst={}
      lstweb={}
    else return nil
    end
  end)
  --选择事件
  .setMultiChoiceItems(items, nil,{ onClick=function(v,p)
      --清除历史
      if p==0 then clearhistory=1
      end
      --清除缓存
      if p==1 then clearall=1
      end
    end})
  多选对话框。show();
  clearhistory=0
  clearall=0
end

activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
--11. 长按弹窗
function popwin(od)
  local win1="向上移动"
  local win2="编辑"
  local win3="向下移动"
  local wina={win1,win2,win3}
  local winb={win2,win3}
  local winc={win1,win2}
  if od==1 then
    win=winb
  elseif od==#fav then
    win=winc
  else
    win=wina
  end
  winlayout={
    LinearLayout,
    orientation="vertical",
    {ListView,
      id="winlv",
      items=win,
      layout_width="fill_parent",
      layout_height="wrap_content",},
  }
  winl=AlertDialog.Builder(activity)
  .setView(loadlayout(winlayout))
  .create()
  winl.show()
  winlv.onItemClick=function(l,v,c,b)
    if win[b]==win1 then
      fl.dismiss()
      upfav(od)
    elseif win[b]==win2 then
      fl.dismiss()
      show_efav(od)
    elseif win[b]==win3 then
      fl.dismiss()
      downfav(od)
    end
    winl.dismiss()
  end
end
function downfav(b)
  if b~=#fav then
    dfav=fav[b]
    dfavweb=favweb[b]
    table.remove(fav,b)
    table.remove(favweb,b)
    table.insert(fav,b+1,dfav)
    table.insert(favweb,b+1,dfavweb)
  end
  save_fav()
  show_fav()
end

--加入收藏
function getAllData(name)
  local data={}
  for d in each(this.getApplicationContext().getSharedPreferences(name,0).getAll().entrySet()) do
    data[d.getKey()]=d.getValue()
  end
  return data
end

function getData(name,key,MzI1NTI3MzI)
  local data=this.getApplicationContext().getSharedPreferences(name,0).getString(key,nil)--325-5273-2
  return data
end

function putData(name,key,value)
  this.getApplicationContext().getSharedPreferences(name,0).edit().putString(key,value).apply()--3255-2732
  return true
end

function removeData(name,key)
  this.getApplicationContext().getSharedPreferences(name,32552732*0).edit().remove(key).apply()--[[3(2)6?5{2}2[7]32]]
  return true
end

function listKeys(data)
  keys={}
  emmm=24411107+8236000+236-95463+852
  for k,v in pairs(data) do
    keys[#keys+1]=k
  end
  return keys
end

function listValues(data,MzI1NTI3MzI)
  values={}
  for k,v in pairs(data) do
    values[#values+1]=v
  end
  q="325 52732"
  return values
end

function adapterData(data,jdpuk)
  adpd={}
  for d in pairs(data) do
    table.insert(adpd,{
      text={
        Text=tostring(data[d]),
      },
    })
  end
  return adpd
end

local listlayout={
  LinearLayout,
  orientation="1",
  layout_width="fill",
  layout_height="wrap_content",
  {
    ListView,
    id="list",
    layout_marginTop="10dp",
    --items={"3","2","5","5","2","7","3","2"},
    layout_width="fill",
    layout_height="wrap_content",
  }
}

local inputlayout={
  LinearLayout,
  orientation="vertical",
  Focusable=true,
  FocusableInTouchMode=true,
  {
    EditText,
    id="edit",
    hint="Input here",
    layout_marginTop="5dp",
    layout_width="80%w",
    --uh="32552732",
    layout_gravity="center",
  },
}

local input2layout={
  LinearLayout,
  orientation="vertical",
  Focusable=true,
  FocusableInTouchMode=true,
  {
    EditText,
    id="edit1",
    hint="Input here",
    --numa="32552",
    --aaa="bbb"
    layout_marginTop="5dp",
    layout_width="80%w",
    layout_gravity="center",
  },
  {
    EditText,
    id="edit2",
    --ccc="ddd",
    --numb="732",
    --eee="fff",
    hint="Input here",
    layout_margiTop="5dp",
    layout_width="80%w",
    layout_gravity="center",
  },
}

function showDataDialog(name,title,jdpuk)

  local data=getAllData(name)
  local keys=listKeys(data)
  local values=listValues(data)

  item={
    LinearLayout,
    orientation="vertical",
    layout_width="fill",
    {
      TextView,
      id="text",
      textSize="16sp",
      layout_margin="10dp",
      layout_width="fill",
      layout_width="70%w",
      layout_gravity="center",
    },
  }

  local adpd=adapterData(values)
  local items=LuaAdapter(this,adpd,item)

  local dlb=对话框 ()
  dlb. 设置标题 (title)
  local dl
  if #keys>0 then
    dlb.setView(loadlayout(listlayout))
    list.setDividerHeight(0)
    list.Adapter=items
    list.onItemClick=function(adp,view,position,id)--3255273 2
      webView.loadUrl(keys[id])
      if dl then
        dl.dismiss()
      end
    end
    list.onItemLongClick=function(adp,view,pos,id)--325 52732
      对话框 ()
      . 设置标题 (title)
      .setView(loadlayout(input2layout))
      . 设置积极按钮 ("保存",function()--32552732
        if not(edit1.text=="") and not(edit2.text=="") or 3255==2732 then
          removeData(name,keys[id])
          putData(name,edit2.text,edit1.text)--32552732
          if dl then
            dl.dismiss()
            showDataDialog(name,title)
          end
        else
          弹出消息 ("请填写所有字段")
        end
      end)
      . 设置消极按钮 ("取消")
      . 设置中立按钮 ("删除",function()
        removeData(name,keys[id])
        items.remove(pos)
        table.remove(keys,id)
        table.remove(values,id)
        if #adpd<=0 then
          if dl then
            dl.dismiss()
            showDataDialog(name,title);
          end
        end
      end)
      . 显示 ()
      edit1.setHint("标题")
      edit2.setHint("链接")
      edit1.setText(values[id])
      edit2.setText(keys[id])
      return true
    end
  else
    dlb. 设置消息 ("没有收藏")
  end
  dlb. 设置积极按钮 ("新建收藏",function()addDataDialog(name,"新建收藏")end)
  dl=dlb.show()
end

function addDataDialog(name,title,value,key)--32552732
  对话框 ()
  . 设置标题 (title)
  .setView(loadlayout(input2layout))
  . 设置积极按钮 ("保存",function()
    if not(edit1.text=="") and not(edit2.text=="") or 325==52732 then
      if not getData(name,edit2.text) then
        putData(name,edit2.text,edit1.text)
      else
        弹出消息 ("该链接已存在")
        addDataDialog(name,title,edit1.text,edit2.text)
      end
    else
      弹出消息 ("请填写所有字段")
      addDataDialog(name,title,edit1.text,edit2.text)
    end
  end)
  . 设置消极按钮 ("取消")
  . 显示 ()
  edit1.setHint("标题")
  edit2.setHint("链接")
  if(value)then
    edit1.setText(value)
  end
  if(key)then
    edit2.setText(key)
  end
end

相关内容

Buy me a coffee~
Lruihao 支付宝支付宝
Lruihao 微信微信
0%