Guest User

Untitled

a guest
Mar 6th, 2025
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Permission to use, copy, modify, and/or distribute this software for
  4. # any purpose with or without fee is hereby granted.
  5. #
  6. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  7. # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
  8. # OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE
  9. # FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
  10. # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  11. # AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  12. # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  13.  
  14. # -----------------------------------------------------------------------------
  15.  
  16. # This is a reference custom action to upload screenshots to Imgur™.
  17. # Users are encouraged to make their own copies to cover their needs
  18. # such as authenticated upload or use different hosting services.
  19.  
  20. # Watch for sensitive content, the uploaded image will be publicly
  21. # available and there is no guarantee it can be certainly deleted.
  22. # Xfce is NOT affiliated with nor this script is approved by Imgur™.
  23. # If you use this script you must agree with Imgur™ Terms of Service
  24. # available at https://imgur.com/tos
  25.  
  26. # -----------------------------------------------------------------------------
  27.  
  28. URL='https://api.imgur.com/3/image'
  29. SCREENSHOT_PATH=$1
  30. CLIENT_ID=$2
  31.  
  32. if [ -z "$SCREENSHOT_PATH" ] || [ -z "$CLIENT_ID" ]; then
  33. zenity --error --text="Arguments are missing"
  34. exit 1
  35. fi
  36.  
  37. #RESPONSE='{"data":{"id":"q9a8Oh4","title":null,"description":null,"datetime":1690124891,"type":"image\/png","animated":false,"width":217,"height":186,"size":593,"views":0,"bandwidth":0,"vote":null,"favorite":false,"nsfw":null,"section":null,"account_url":null,"account_id":0,"is_ad":false,"in_most_viral":false,"has_sound":false,"tags":[],"ad_type":0,"ad_url":"","edited":"0","in_gallery":false,"deletehash":"b0AjSDJjSU4iyhE","name":"","link":"https:\/\/i.imgur.com\/q9a8Oh4.png"},"success":true,"status":200}'
  38. #RESPONSE='{"data":{"error":{"code":1003,"message":"File type invalid (1)","type":"ImgurException","exception":[]},"request":"\/3\/image","method":"POST"},"success":false,"status":400}'
  39. RESPONSE=$(curl --silent --location "$URL" --header "Authorization: Client-ID $CLIENT_ID" --form "image=@$SCREENSHOT_PATH")
  40. STATUS=$(echo "$RESPONSE" | jq -r .status)
  41.  
  42. if [ -z "$STATUS" ] || [ $STATUS -ne 200 ]; then
  43. ERROR=$(echo "$RESPONSE" | jq -r .data.error.message)
  44. zenity --error --text="Failed to upload screenshot:\n$ERROR"
  45. exit 1
  46. fi
  47.  
  48. LINK="https://imgur.com/$(echo "$RESPONSE" | jq -r .data.id).png"
  49. DELETE="https://imgur.com/delete/$(echo "$RESPONSE" | jq -r .data.deletehash)"
  50. LOG_DIRECTORY="${XDG_DATA_HOME:-$HOME/.local/share}/xfce4"
  51. LOG="$LOG_DIRECTORY/xfce4-screenshooter-imgur.log"
  52.  
  53. # Add link to clipboard
  54. echo "$LINK" | xclip -selection c
  55.  
  56. # Add links to log
  57. mkdir -p "$LOG_DIRECTORY"
  58. echo "---
  59. $(date '+%x %X')
  60. Link: $LINK
  61. Delete: $DELETE" >> "$LOG"
  62.  
  63. # Show dialog with links
  64. zenity --info --title="Screenshot uploaded" --text="Link: <a href='$LINK'>$LINK</a>
  65. Delete: <a href='$DELETE'>$DELETE</a>
  66.  
  67. Link copied to clipboard. Links stored in:
  68. $LOG"
Advertisement
Add Comment
Please, Sign In to add comment