Last active
April 18, 2017 23:46
-
-
Save noromanba/d007fd37daa55a12681db7c7cd800b8e to your computer and use it in GitHub Desktop.
select links on dropbox.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // @name dropbox selectlink | |
| // @description select links on dropbox.com | |
| // @version 2016.10.30.0 | |
| // @homepage https://gist.github.com/noromanba/d007fd37daa55a12681db7c7cd800b8e | |
| // @license MIT License https://nrm.mit-license.org/2016 | |
| // @author noromanba http://noromanba.flavors.me | |
| (() => { | |
| 'use strict'; | |
| //*/ | |
| // if `Array.from` is *NOT* native, in some cases ignoring 2nd map-func e.g. | |
| // https://www.dropbox.com/sh/[<DIR_HASH>]/<HASH>/<FILE_NAME> | |
| // Prototype.Version | |
| // "1.7" | |
| // | |
| // Array.from | |
| // function $A(e){if(!e)return[];if("toArray"in Object(e))return e.toArray();for(var t=e.length||0,n=new Array(t);t--;)n[t]=e[t];return n} | |
| // so always return raw array c.f. | |
| // http://api.prototypejs.org/language/Array/from/ | |
| // Array.from(iterable) → Array | |
| // https://github.com/sstephenson/prototype/blob/5fddd3e/src/prototype/lang/array.js#L104 | |
| // Array.from = $A; | |
| // WTF, Global Object Pollution must die | |
| // | |
| // recovering native methods c.f. | |
| // https://stackoverflow.com/questions/8580431/recovering-built-in-methods-that-have-been-overwritten#8580576 | |
| if (!Array.from.toString().includes('[native code]')) { | |
| const sandbox = document.head.appendChild(document.createElement('iframe')); | |
| Array.from = sandbox.contentWindow.Array.from; | |
| } | |
| const urls = Array.from(document.body.querySelectorAll([ | |
| `a[href^="${location.origin + location.pathname.split('/').slice(0, 3).join('/')}"]` | |
| ]), link => { | |
| const url = new URL(link.href); | |
| url.search = ''; | |
| return url.href; | |
| }); | |
| /*/ | |
| // Global Object Pollution safe; not use 2nd args | |
| const urls = Array.from(document.body.querySelectorAll([ | |
| `a[href^="${location.origin + location.pathname.split('/').slice(0, 3).join('/')}"]` | |
| ])).map(link => { | |
| const url = new URL(link.href); | |
| url.search = ''; | |
| return url.href; | |
| }); | |
| //*/ | |
| console && console.dir && console.dir(urls.join(' ')); | |
| return urls.join(' '); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment