|
class GetAllDirectories { |
|
constructor(diretoryName, siteUrl, delay){ |
|
this.diretoryName = diretoryName; |
|
this.siteUrl = siteUrl || ''; |
|
this.delay = delay || 6000; |
|
this.directories = new Set(); |
|
this.openFirstFolder() |
|
} |
|
|
|
openFirstFolder() { |
|
const _self = this; |
|
|
|
$('.directory').each(function() { |
|
if ($(this).find('> a').text() === _self.diretoryName) { |
|
$(this).find('> a').click(); |
|
setTimeout(() => { |
|
_self.openSubFolders($(this)); |
|
}, _self.delay) |
|
} |
|
}) |
|
} |
|
|
|
openSubFolders(folderElement){ |
|
const _self = this; |
|
folderElement.addClass('getpages-folder'); |
|
_self.directories.add(_self.getFolderPath(folderElement)); |
|
|
|
folderElement.find('> ul > li.directory').each(function(index) { |
|
const subFolder = $(this); |
|
setTimeout(() => { |
|
subFolder.find('> a').click(); |
|
console.log(subFolder.find('> a').text()) |
|
setTimeout(() => { |
|
_self.openSubFolders(subFolder) |
|
}, _self.delay); |
|
}, _self.delay + (index * 2000)) |
|
}) |
|
} |
|
|
|
getFolderPath(folderElement){ |
|
let paths = []; |
|
|
|
//current folder path |
|
paths.push(folderElement.find('> a').text()); |
|
|
|
//parent folders path |
|
folderElement.parents('.getpages-folder').each(function(){ |
|
paths.push($(this).find('> a').text()); |
|
}); |
|
|
|
return this.siteUrl + '/' + paths.reverse().join('/') |
|
} |
|
} |
|
|
|
/** |
|
* set the selectedDirectory variable at the bottom of the script |
|
* set the websiteurl variable at the bottom of the script |
|
* Enter in /admin/a |
|
* open CMS folder |
|
* open Sites and channels folder |
|
* open selected website |
|
* open the root folder "/" |
|
* run the script |
|
*/ |
|
|
|
const selectedDirectory = 'tree'; |
|
const websiteurl = 'http://corebiz.com.br'; //do not add the end slash "/" |
|
|
|
var a = new GetAllDirectories(selectedDirectory, websiteurl); |
|
|
|
/** |
|
* when it stops to run, all the subfolders of selectedDirectory |
|
* will be in this Set (very similar to array) |
|
*/ |
|
console.log(a.directories); |
|
|
|
/** |
|
* converting to array and print as string to copy |
|
*/ |
|
JSON.stringify([...a.directories]) |