Advertisement
Guest User

TumblrAccessibilityChecker.ps1

a guest
Mar 14th, 2022
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #=====================================================================================================
  2. # Author:  Dan(v)
  3. # Date:    14/03/2022
  4. # Purpose: Read a clipboard containing a Tumblr (or Tumbex) URL
  5. #          From that URL, determine whether that Tumblr account
  6. #          has an accessible 'Archive' page or whether
  7. #          (like the majority of Tumblr pages these days) that account
  8. #          is blocked, at least to non-Tumblr users.
  9. #=====================================================================================================
  10. # For matching to Tumbex URLs
  11. $RegExTumbexURL = '^(http|https)s?:\/\/www.tumbex.com\/(?<PageName>.*.tumblr)\/.*$'
  12. # For matching to Tumbex URLs
  13. $RegExTumblrURL = '^https:\/\/(?<PageName>.*.tumblr).com.*$'
  14. # For matching with Tumblr page base URL, i.e. minus the 'archive' element
  15. $RegExTumblrBasePageURL = '^https:\/\/(?<PageName>.*.tumblr).com\/$'
  16.  
  17. # You can define your browser preference here, either firefox or chrome
  18. $BrowserPreference = 'firefox' # or 'chrome'
  19.  
  20. Clear-Host
  21.  
  22. # Read a Tumbex URL from clipboard
  23. $UrlFromClipboard = Get-Clipboard
  24.  
  25. Write-Output "Running script ... "
  26.  
  27. # Seek a match to tumblr URL or a tumbex URL, can work with either.
  28. if (($UrlFromClipboard -match $RegExTumbexURL) -or ($UrlFromClipboard -match $RegExTumblrURL))
  29. {
  30.  
  31.     # Retrieve the matched value of the named capture group 'PageName' from the regular expression.
  32.     $PageName = $Matches['PageName']
  33.     Write-Output "Check page name:  $PageName"
  34.    
  35.     # I like working with the Tumblr 'archive' page, so that's what I'm constructing and will visit
  36.     # programmatically.
  37.     $TumblrArchiveUrl = "https://$($PageName).com/archive"
  38.  
  39.     # Check if the Tumblr archive page results in an accessible page or whether one of the countless
  40.     # Tumblr blogs 'blocked' by safe mode or some other crap.
  41.     try
  42.     {
  43.         $WebResponse = Invoke-WebRequest -Uri $TumblrArchiveUrl
  44.     }
  45.     catch
  46.     {
  47.         Write-Warning "URL inaccessible, possibly in wrong format, missing characters perhaps?"
  48.     }
  49.  
  50.     # Check the 'links href' property of the web response object. We are expecting one of the link's 'href'  
  51.     # properties will match that actual tumblr base page URL (minus '/archive')
  52.     $Links = $WebResponse.Links.href
  53.    
  54.     # Check count of links, should be just 1 and should match the Tumblr base url for this page.
  55.     if (($Links.Count -eq 1) -and ($Links -match $RegExTumblrBasePageURL))
  56.     {
  57.         Write-Output "We got an accessible page!  Opening page in $($BrowserPreference) ...."
  58.  
  59.         # Open URL in users browser of choice, defined via variable near top of script
  60.         # Piping to 'Out-Null' just to suppress a line of process information.
  61.         [system.Diagnostics.Process]::Start($BrowserPreference,$TumblrArchiveUrl) | Out-Null
  62.     }
  63.     else
  64.     {
  65.         Write-Output "Page inaccessible, sorry"
  66.     }
  67. }
  68. else
  69. {
  70.     Write-Output "Does not appear to be an expected Tumbex URL...."
  71. }
  72. Write-Output "Script ended"
  73. #=====================================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement