forked from githubdulong/Script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitHub.scriptable
More file actions
12 lines (11 loc) · 7.56 KB
/
Copy pathGitHub.scriptable
File metadata and controls
12 lines (11 loc) · 7.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
{
"always_run_in_app" : false,
"icon" : {
"color" : "deep-purple",
"glyph" : "code-branch"
},
"name" : "GitHub",
"script" : "\/\/ Scriptable使用的变量。\n\/\/ 这些必须在文件的顶部。不要编辑。\n\/\/ 图标符号:盲文;图标颜色:深灰色;\n\/**\n * @版本 1.0.0\n * @作者 Honye\n *\/\n\n\/**\n * @Param {number} [高度] 以像素为单位的屏幕高度\n *\/\nconst phoneSize = (height) => {\n const phones = {\n \/** 12 Pro Max *\/\n 2778: {\n small: 510,\n medium: 1092,\n large: 1146,\n left: 96,\n right: 678,\n top: 246,\n middle: 882,\n bottom: 1518\n },\n \/** 12 and 12 Pro *\/\n 2532: {\n small: 474,\n medium: 1014,\n large: 1062,\n left: 78,\n right: 618,\n top: 231,\n middle: 819,\n bottom: 1407\n },\n \/** 11 Pro Max, XS Max *\/\n 2688: {\n small: 507,\n medium: 1080,\n large: 1137,\n left: 81,\n right: 654,\n top: 228,\n middle: 858,\n bottom: 1488\n },\n \/** 11, XR *\/\n 1792: {\n small: 338,\n medium: 720,\n large: 758,\n left: 55,\n right: 437,\n top: 159,\n middle: 579,\n bottom: 999\n },\n \/** 11 Pro, XS, X, 12 mini *\/\n 2436: {\n small: 465,\n medium: 987,\n large: 1035,\n x: {\n left: 69,\n right: 591,\n top: 213,\n middle: 783,\n bottom: 1353\n },\n mini: {\n left: 69,\n right: 591,\n top: 231,\n middle: 801,\n bottom: 1371\n }\n },\n \/** Plus phones *\/\n 2208: {\n small: 471,\n medium: 1044,\n large: 1071,\n left: 99,\n right: 672,\n top: 114,\n middle: 696,\n bottom: 1278\n },\n \/** SE2 and 6\/6S\/7\/8 *\/\n 1334: {\n small: 296,\n medium: 642,\n large: 648,\n left: 54,\n right: 400,\n top: 60,\n middle: 412,\n bottom: 764\n },\n \/** SE1 *\/\n 1136: {\n small: 282,\n medium: 584,\n large: 622,\n left: 30,\n right: 332,\n top: 59,\n middle: 399,\n bottom: 399\n },\n \/** 11 and XR in Display Zoom mode *\/\n 1624: {\n small: 310,\n medium: 658,\n large: 690,\n left: 46,\n right: 394,\n top: 142,\n middle: 522,\n bottom: 902\n },\n \/** Plus in Display Zoom mode *\/\n 2001: {\n small: 444,\n medium: 963,\n large: 972,\n left: 81,\n right: 600,\n top: 90,\n middle: 618,\n bottom: 1146\n }\n };\n height = height || Device.screenResolution().height;\n const scale = Device.screenScale();\n\n if (config.runsInWidget) {\n const phone = phones[height];\n if (phone) {\n return phone\n }\n\n const pc = {\n small: 164 * scale,\n medium: 344 * scale,\n large: 354 * scale\n };\n return pc\n }\n\n \/\/ in app screen fixed 375x812 pt\n return {\n small: 155 * scale,\n medium: 329 * scale,\n large: 345 * scale\n }\n};\n\nlet user = 'githubdulong';\nlet columns = 20;\nconst widgetFamily = config.widgetFamily || 'medium';\nlet theme = 'system';\nconst themes = {\n dark: {\n background: new Color('#282828', 1),\n colors: ['#45454a', '#9be9a8', '#40c463', '#30a14e', '#216e39']\n },\n light: {\n background: new Color('#ffffff', 1),\n colors: ['#ebedf0', '#9be9a8', '#40c463', '#30a14e', '#216e39']\n }\n};\nif (config.runsInWidget) {\n [\n user = user,\n theme = theme\n ] = (args.widgetParameter || '')\n .split(',')\n .map(item => item.trim() || undefined);\n columns = widgetFamily === 'small' ? 9 : columns;\n}\nconst gap = { x: 3, y: 2 };\n\nconst getImage = async (url) => {\n const request = new Request(url);\n const image = await request.loadImage();\n return image\n};\n\nconst screen = Device.screenResolution();\nconst scale = Device.screenScale();\nconst widgetWidth = phoneSize(screen.height)[widgetFamily] \/ scale;\nconst rectWidth = (widgetWidth - 24 - gap.x * (columns - 1)) \/ columns;\nconst url = `https:\/\/github.com\/${user}`;\n\nconst widget = new ListWidget();\nwidget.url = url;\nwidget.backgroundColor = theme === 'system'\n ? Color.dynamic(\n themes.light.background,\n themes.dark.background\n )\n : themes[theme].background;\n\nconst req = new Request(url);\nreq.headers = {\n cookie: '_octo=GH1.1.1539639820.1577368057; _ga=GA1.2.2040897722.1577368108; tz=Asia%2FShanghai; _device_id=7eef997fa1bfbba0d352348e6c677334; ignored_unsupported_browser_notice=false; tz=Asia%2FShanghai; user_session=he6iH5ZsE-PG5s1GeHJwydUNTgTkP3foK1i-1gLLEgrASXcb; __Host-user_session_same_site=he6iH5ZsE-PG5s1GeHJwydUNTgTkP3foK1i-1gLLEgrASXcb; logged_in=yes; dotcom_user=Honye; color_mode=%7B%22color_mode%22%3A%22light%22%2C%22light_theme%22%3A%7B%22name%22%3A%22light%22%2C%22color_mode%22%3A%22light%22%7D%2C%22dark_theme%22%3A%7B%22name%22%3A%22dark%22%2C%22color_mode%22%3A%22dark%22%7D%7D; has_recent_activity=1; _gh_sess=zNp4F9ia6hAFRiEE6exEsm4FZYz6VDu0S9l8jLnEVyDApj9y1SNlVxG8mlVHpBETxUWaz%2FPAXJYW3Pr4GltoXR6%2FfAcj84Y2lkFb1TKaIdmXFTN6K%2F9tCwjx60PsD3DG86RdKSApKT%2B26e1wXl%2FHFHEs2G9S1zXHTKdRhCwBzR0cQpl3ZPZgljHdGDgFL9mVWW8jOzbtXfDGAHrJjh9q3cAuuIOoOl%2B%2Bpbj678ve4X2FPpCtjtN20TgWHFNSW7qFyKqCLLld0%2FpEofC8C6Yh3QRrOf7NcUO0hsazrfwwXhalN09lXHM65lYrVHBrxzsIcmldMCq6R7FtNd7nxsMEI3lVV%2FSH%2BUKNQ78xqtnGojF71ptd8Pzr2VY6aWdtCEQZ4PvfpMnJB8jxWCD7lr4XIv0nDP7bv3YLDwZCgEqIHKuVJMPYCPhyj%2F59et6kXZUh--teNA69tt8cQfyR5s--NgLNgyFA1Wfd9k8354EM8A%3D%3D',\n 'cache-control': 'max-age=0',\n 'if-none-match': 'W\/\"cff70e46ae5c8359d3d6d2f8e8256fae\"'\n};\nconst resp = await req.loadString();\n\nconst avatar = resp.match(\/og:image\" content=\"([^\"]+)\/)[1];\nconst name = resp.match(\/<title>.+\\((.+)\\).*<\\\/title>\/)?.[1] || user;\nconst countText = resp.match(\/\\d{1,},*\\d*\\s+contributions\/)[0].replace(\/\\s+contributions\/, ' ');\nlet contributions = resp.match(\/<g transform=\"translate(.|\\n)+?<\\\/g>\/g);\ncontributions = contributions.slice(-columns).join('\\n');\nlet colorsData = contributions.match(\/data-level=\"\\d+\/g).join('\\n');\ncolorsData = colorsData.replace(\/data-level=\"\/g, '').split('\\n');\n\nconst head = widget.addStack();\nhead.layoutHorizontally();\nhead.centerAlignContent();\n\n\/\/ avatar\nconst imageAvatar = head.addImage(await getImage(avatar));\nimageAvatar.imageSize = new Size(20, 20);\nimageAvatar.cornerRadius = 10;\nhead.addSpacer(3);\n\n\/\/ 用户名\nconst textName = head.addText(name.toUpperCase());\ntextName.lineLimit = 1;\ntextName.minimumScaleFactor = 2;\ntextName.font = Font.boldSystemFont(13);\ntextName.textColor = new Color('#aeaeb7', 1);\nhead.addSpacer(3);\n\n\/\/ 捐款计数\nif (widgetFamily !== 'small') {\n const textCount = head.addText(`(${countText}贡献值)`.toUpperCase());\n textCount.font = Font.systemFont(10);\n textCount.textColor = new Color('#aeaeb7', 1);\n}\n\nwidget.addSpacer(10);\n\nconst ls = [];\nfor (let i = 0; i < 7; ++i) {\n ls.push(widget.addStack());\n if (i < 6) {\n widget.addSpacer(2);\n }\n}\n\nfor (const [index, level] of colorsData.entries()) {\n const row = ls[index % 7];\n const rect = row.addStack();\n rect.size = new Size(rectWidth, rectWidth);\n rect.cornerRadius = 2;\n rect.backgroundColor = theme === 'system'\n ? Color.dynamic(\n new Color(themes.light.colors[level], 1),\n new Color(themes.dark.colors[level], 1)\n )\n : new Color(themes[theme].colors[level], 1);\n\n if (index < 7 * (columns - 1)) {\n row.addSpacer(3);\n }\n}\n\nScript.setWidget(widget);\nwidget.presentMedium();\n",
"share_sheet_inputs" : [
]
}