nblog_duo 0.0.53 → 0.0.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nblog_duo.rb +337 -213
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e203c5f630ea3d462073545b7869ac705f6f642716b3af48f18653c1a4f2a93
4
- data.tar.gz: b758cce302bec173766367b4c1998b4a5a27c00052db46d83abc66d8d49e7d8a
3
+ metadata.gz: 398dd3e77cc0d829473c76405153daa2f032f5f3ee16a7ede96ffd178d3de231
4
+ data.tar.gz: d93f4a474d8c60449db041bcd23076ae4812da9cbf07f969fa855d010ad45970
5
5
  SHA512:
6
- metadata.gz: 44c6bba61bac3781ddf3de50309be9db5e08e9525df7f7ece9d98c20eac2a0a20835c586dd2ab8d4630128ecddd8f18e827058a65a204aa6b682d4e7ae9c65e6
7
- data.tar.gz: 44fb69ff106332d47357547c99582cf679a11b78ae89f627b6a39962c9f9699376923a0dcf1a9d5a450d9dabc2da34ca215d8e2bf217e54b6657b4d64be6f504
6
+ metadata.gz: 71a36c830723a73578cb68eda97403aa2b2d237fa9ea803169a2e9d1f2b288a524a7f51e78785c15ed582e77ce00741d0d92fa410ff97abe077ab98e13944d56
7
+ data.tar.gz: 428e7af6345dfa93cd7b9e3e798ed9111aa57c659e0ca6f6e319f0b3493e5bc86bb9b6251a00543ba2758ff379cd3a889a467ec5e9a9ec00cf251f9d012940d1
data/lib/nblog_duo.rb CHANGED
@@ -747,58 +747,182 @@ class Naver
747
747
  path = URI.decode_www_form(path)[0][0]
748
748
  if option['라이브러리사용안함'] == 'true'
749
749
  # 현재 탭의 URL을 가져오기
750
-
750
+ puts '라이브러리에서 제외되도록 작업을 실행합니다(새로운 창을 생성합니다)'
751
751
  posting_url = @driver.current_url
752
752
  @driver.execute_script("window.open('#{posting_url}');")
753
753
  sleep(1)
754
754
  @driver.switch_to.window(@driver.window_handles[1])
755
- wait = Selenium::WebDriver::Wait.new(timeout: 10)
756
- iframe = wait.until { @driver.find_element(id: 'mainFrame') }
757
- @driver.switch_to.frame(iframe)
758
755
  begin
759
- wait = Selenium::WebDriver::Wait.new(:timeout => 7)
760
- wait.until { @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]') }
761
- @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]').click
756
+ wait = Selenium::WebDriver::Wait.new(timeout: 10)
757
+ iframe = wait.until { @driver.find_element(id: 'mainFrame') }
758
+ @driver.switch_to.frame(iframe)
759
+ begin
760
+ wait = Selenium::WebDriver::Wait.new(:timeout => 7)
761
+ wait.until { @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]') }
762
+ @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]').click
763
+ sleep(1)
764
+ rescue
765
+ end
766
+ @driver.execute_script(<<~JS)
767
+ window.URL.createObjectURL = function() {};
768
+ HTMLInputElement.prototype.click = function() {
769
+ console.log("File dialog suppressed");
770
+ };
771
+ JS
762
772
  sleep(1)
763
- rescue
764
- end
765
- @driver.action.key_down(:control).key_down(:alt).send_keys('i').key_up(:alt).key_up(:control).perform
766
- sleep(1)
767
- Clipboard.copy(path.split('/').join("\\"))
768
- key_down('ctrl')
769
- key_stroke('v')
770
- key_up('ctrl')
771
- sleep(1)
772
- key_stroke('enter')
773
- sleep(2)
774
- @driver.action.send_keys(:up).perform
775
- sleep(1)
776
- @driver.action.key_down(:control).send_keys('c').key_up(:control).perform
777
- sleep(1)
778
- @driver.switch_to.default_content()
779
- @driver.close
780
- sleep(1)
781
- @driver.switch_to.window(@driver.window_handles[0])
782
- wait = Selenium::WebDriver::Wait.new(timeout: 10)
783
- iframe = wait.until { @driver.find_element(id: 'mainFrame') }
784
- @driver.switch_to.frame(iframe)
785
- #@driver.action.key_down(:control).send_keys('v').key_up(:control).perform
786
- key_down('ctrl')
787
- key_stroke('v')
788
- key_up('ctrl')
789
- sleep(1)
773
+
774
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
775
+ # 요소가 나타날 때까지 기다립니다.
776
+ wait.until { @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]') }
777
+ # 해당 버튼을 찾고 클릭
778
+ image_button = @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]')
779
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", image_button) # 크롤 이동
780
+ sleep(1)
781
+ @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]').click
782
+ sleep(1)
783
+
784
+ # 파일 경로 변환 (슬래시 -> 백슬래시)
785
+ file_path = path.split('/').join("\\") # 윈도우 스타일 경로로 변환
786
+ sleep(1)
787
+ # 파일 입력 필드 찾기 (input[type="file"])
788
+ file_input = @driver.find_element(:id, 'hidden-file')
789
+ sleep(1)
790
+ # send_keys로 파일 경로를 직접 입력하여 파일 업로드
791
+ file_input.send_keys(file_path)
792
+ sleep(3)
793
+ @driver.action.key_down(:up).key_up(:up).perform
794
+ sleep(1)
795
+
796
+ begin
797
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
798
+ #요소가 나타날 때까지 60초 동안 기다립니다.
799
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//button[@data-name="image-resizing"]') }
800
+ element = @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//button[@data-name="image-resizing"]')
801
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", element) # 크롤 이동
802
+ sleep(1)
803
+ aria_expanded = element.attribute('aria-expanded')
804
+ if aria_expanded == 'false'
805
+ element.click
806
+ sleep(1) # 클릭 후 잠시 대기
807
+ else
808
+ end
809
+
810
+ begin
811
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
812
+ #요소가 나타날 때까지 60초 동안 기다립니다.
813
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]') }
814
+ sleep(1)
815
+ @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]').click
816
+ sleep(1)
817
+ @driver.action.key_down(:enter).key_up(:enter).perform #엔터
818
+ sleep(1)
819
+ rescue
820
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
821
+ #요소가 나타날 때까지 60초 동안 기다립니다.
822
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]//span[@class="se-custom-layer-resizing-reset-label" and text()="초기화"]') }
823
+ sleep(1)
824
+ @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]//span[@class="se-custom-layer-resizing-reset-label" and text()="초기화"]').click
825
+ sleep(1)
826
+ @driver.action.key_down(:enter).key_up(:enter).perform #엔터
827
+ sleep(1)
828
+ end
829
+ rescue
830
+ @driver.action.key_down(:down).key_up(:down).perform
831
+ end
832
+ sleep(2)
833
+ @driver.action.send_keys(:up).perform
834
+ sleep(1)
835
+ @driver.action.key_down(:control).send_keys('c').key_up(:control).perform
836
+ sleep(1)
837
+ @driver.switch_to.default_content()
838
+ @driver.close
839
+ sleep(1)
840
+ @driver.switch_to.window(@driver.window_handles[0])
841
+ wait = Selenium::WebDriver::Wait.new(timeout: 10)
842
+ iframe = wait.until { @driver.find_element(id: 'mainFrame') }
843
+ @driver.switch_to.frame(iframe)
844
+ @driver.action.key_down(:control).send_keys('v').key_up(:control).perform
845
+ sleep(1)
846
+ rescue => e
847
+ @driver.quit
848
+ puts '이미지 등록실패! 인터넷 접속 불량 및 로딩 지연 다음 작업을 실행합니다.'
849
+ return 0
850
+ end
790
851
 
791
852
  else
792
- #@driver.find_element(:xpath, '//*[@id="'+page_id+'"]/div[1]/div/header/div[1]/ul/li[1]/button').click
793
- @driver.action.key_down(:control).key_down(:alt).send_keys('i').key_up(:alt).key_up(:control).perform
794
- sleep(2)
795
- Clipboard.copy(path.split('/').join("\\"))
796
- key_down('ctrl')
797
- key_stroke('v')
798
- key_up('ctrl')
853
+ @driver.execute_script(<<~JS)
854
+ window.URL.createObjectURL = function() {};
855
+ HTMLInputElement.prototype.click = function() {
856
+ console.log("File dialog suppressed");
857
+ };
858
+ JS
799
859
  sleep(1)
800
- key_stroke('enter')
801
- sleep(2)
860
+ begin
861
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
862
+ # 요소가 나타날 때까지 기다립니다.
863
+ wait.until { @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]') }
864
+ # 해당 버튼을 찾고 클릭
865
+ image_button = @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]')
866
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", image_button) # 크롤 이동
867
+ sleep(1)
868
+ @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]').click
869
+ sleep(1)
870
+
871
+
872
+ # 파일 경로 변환 (슬래시 -> 백슬래시)
873
+ file_path = path.split('/').join("\\") # 윈도우 스타일 경로로 변환
874
+ sleep(1)
875
+ # 파일 입력 필드 찾기 (input[type="file"])
876
+ file_input = @driver.find_element(:id, 'hidden-file')
877
+ sleep(1)
878
+ # send_keys로 파일 경로를 직접 입력하여 파일 업로드
879
+ file_input.send_keys(file_path)
880
+ sleep(3)
881
+ @driver.action.key_down(:up).key_up(:up).perform
882
+ sleep(1)
883
+
884
+ begin
885
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
886
+ #요소가 나타날 때까지 60초 동안 기다립니다.
887
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//button[@data-name="image-resizing"]') }
888
+ element = @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//button[@data-name="image-resizing"]')
889
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", element) # 크롤 이동
890
+ sleep(1)
891
+ aria_expanded = element.attribute('aria-expanded')
892
+ if aria_expanded == 'false'
893
+ element.click
894
+ sleep(1) # 클릭 후 잠시 대기
895
+ else
896
+ end
897
+
898
+ begin
899
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
900
+ #요소가 나타날 때까지 60초 동안 기다립니다.
901
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]') }
902
+ sleep(1)
903
+ @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]').click
904
+ sleep(1)
905
+ @driver.action.key_down(:enter).key_up(:enter).perform #엔터
906
+ sleep(1)
907
+ rescue
908
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
909
+ #요소가 나타날 때까지 60초 동안 기다립니다.
910
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]//span[@class="se-custom-layer-resizing-reset-label" and text()="초기화"]') }
911
+ sleep(1)
912
+ @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]//span[@class="se-custom-layer-resizing-reset-label" and text()="초기화"]').click
913
+ sleep(1)
914
+ @driver.action.key_down(:enter).key_up(:enter).perform #엔터
915
+ sleep(1)
916
+ end
917
+ rescue
918
+ @driver.action.key_down(:down).key_up(:down).perform
919
+ end
920
+ rescue => e
921
+ @driver.close
922
+ puts '이미지 등록실패! 인터넷 접속 불량 및 로딩 지연 다음 작업을 실행합니다.'
923
+ return 0
924
+ end
925
+
802
926
  end
803
927
 
804
928
 
@@ -830,217 +954,217 @@ class Naver
830
954
  sleep(1)
831
955
  end
832
956
 
833
-
834
- # end
835
- # components_value['src'] = 'https://blogfiles.pstatic.net'+image_data['item']['url']+'?type=w1'
836
- # components_value['internalResource'] = true
837
- # components_value['represent'] = true
838
- # components_value['path'] = image_data['item']['url']
839
- # components_value['domain'] = "https://blogfiles.pstatic.net"
840
- # components_value['fileSize'] = image_data['item']['fileSize'].to_i
841
- # components_value['width'] = image_data['item']['width'].to_i
842
- # components_value['widthPercentage'] = 0
843
- # components_value['height'] = image_data['item']['height'].to_i
844
- # components_value['fileName'] = image_data['item']['fileName'].to_i
845
- # components_value['caption'] = nil
846
- # if i2.to_s.split('href="')[1] != nil
847
- # components_value['link'] = CGI.unescape(i2.to_s.split('href="')[1].split('"')[0])
848
- # end
849
- # components_value['format'] = 'normal'
850
- # components_value['displayFormat'] = 'normal'
851
- # components_value['imageLoaded'] = true
852
- # components_value['contentMode'] = 'fit'
853
- # components_value['origin'] = {
854
- # 'srcFrom' => 'local',
855
- # '@ctype' => 'imageOrigin'
856
- # }
857
- # components_value['@ctype'] = 'image'
957
+
858
958
  elsif i2.to_s.include?('<video')
859
959
  path = i2.to_s.split('src="')[1].split('"')[0]
860
960
  path = URI.decode_www_form(path)[0][0]
961
+ begin
962
+ @driver.find_element(:xpath, '//*[@id="'+page_id+'"]/div[1]/div/header/div[1]/ul/li[3]/button').click
963
+ sleep(3)
964
+
965
+
966
+ @driver.execute_script(<<~JS)
967
+ window.URL.createObjectURL = function() {};
968
+ HTMLInputElement.prototype.click = function() {
969
+ console.log("File dialog suppressed");
970
+ };
971
+ JS
972
+ sleep(1)
973
+ # 파일 업로드 버튼 클릭 (이제 파일 선택 창이 뜨지 않음)
974
+ @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/fieldset/div[1]/button[1]').click
975
+ sleep(3)
976
+
977
+ file_path = path.split('/').join("\\") # 윈도우 스타일 경로로 변환
978
+ sleep(1)
979
+ # 파일 입력 필드 찾기 (input[type="file"])
980
+ file_input = @driver.find_element(:id, "hidden-input")
981
+ sleep(1)
982
+ # send_keys로 파일 경로를 직접 입력하여 파일 업로드
983
+ file_input.send_keys(file_path)
984
+ sleep(3)
985
+
986
+ @driver.find_element(:xpath, '//*[@id="nvu_inp_box_title"]').send_keys(title)
987
+ sleep(1)
988
+
989
+ @driver.find_element(:xpath, '//*[@id="nvu_inp_box_description"]').send_keys(title)
990
+ sleep(1)
991
+
992
+
993
+
994
+
995
+ tags2 = option['tag'].to_s
996
+ tag_mm2 = Array.new
997
+ tags2.split(',').each do |tag_value|
998
+ tag_mm2 << ''+tag_value
999
+ end
1000
+
1001
+ @driver.find_element(:xpath, '//*[@id="nvu_inp_box_tag"]').send_keys(tag_mm2.join("\n")+"\n")
1002
+ sleep(1)
1003
+
861
1004
 
862
- @driver.find_element(:xpath, '//*[@id="'+page_id+'"]/div[1]/div/header/div[1]/ul/li[3]/button').click
863
- sleep(3)
864
- @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/fieldset/div[1]/button[1]').click
865
- sleep(3)
866
-
867
- Clipboard.copy(path.split('/').join("\\"))
868
- key_down('ctrl')
869
- key_stroke('v')
870
- key_up('ctrl')
871
- sleep(3)
872
- key_stroke('enter')
873
- sleep(3)
874
-
875
- for n in 1..10
876
- puts @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/div[1]/ul/li/div/button[1]/div[2]/em').text
877
- if @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/div[1]/ul/li/div/button[1]/div[2]/em').text == '업로드 완료'
878
- break
1005
+ for n in 1..10
1006
+ begin
1007
+ puts @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/div[1]/ul/li/div/button[1]/div[2]/em').text
1008
+ if @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/div[1]/ul/li/div/button[1]/div[2]/em').text == '업로드 완료'
1009
+ break
1010
+ end
1011
+ sleep(10)
1012
+ rescue
1013
+ end
879
1014
  end
880
- sleep(10)
1015
+
1016
+
1017
+ @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[3]/button/span').click
1018
+ sleep(3)
1019
+ rescue => e
1020
+ @driver.close
1021
+ puts '동영상 등록실패! 인터넷 접속 불량 및 로딩 지연 다음 작업을 실행합니다.'
1022
+ return 0
881
1023
  end
882
- @driver.find_element(:xpath, '//*[@id="nvu_inp_box_title"]').send_keys(title)
883
- sleep(5)
884
- @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[3]/button/span').click
885
- sleep(3)
886
-
887
1024
 
888
1025
  elsif i2.to_s.include?('<slide')
889
1026
  if option['라이브러리사용안함'] == 'true'
890
-
1027
+ puts '라이브러리에서 제외되도록 작업을 실행합니다(새로운 창을 생성합니다)'
891
1028
  posting_url = @driver.current_url
892
1029
  @driver.execute_script("window.open('#{posting_url}');")
893
1030
  sleep(1)
894
- @driver.switch_to.window(@driver.window_handles[1])
895
- wait = Selenium::WebDriver::Wait.new(timeout: 10)
896
- iframe = wait.until { @driver.find_element(id: 'mainFrame') }
897
- @driver.switch_to.frame(iframe)
1031
+
898
1032
  begin
1033
+ @driver.switch_to.window(@driver.window_handles[1])
1034
+ wait = Selenium::WebDriver::Wait.new(timeout: 10)
1035
+ iframe = wait.until { @driver.find_element(id: 'mainFrame') }
1036
+ @driver.switch_to.frame(iframe)
1037
+
1038
+
899
1039
  wait = Selenium::WebDriver::Wait.new(:timeout => 7)
900
1040
  wait.until { @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]') }
901
1041
  @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]').click
902
1042
  sleep(1)
903
- rescue
904
- end
905
-
906
- slide_content = i2.to_s.split('<slide>').last.split('</slide>').first.strip
907
- paths = slide_content.scan(/"([^"]+)"/).flatten # 큰따옴표로 감싸진 경로만 추출
1043
+
908
1044
 
909
- # 2. 전체 경로를 추출하여 윈도우 경로로 변환
910
- full_paths = paths.map { |path| path.strip.gsub('/', '\\') } # 윈도우 경로 구분자로 변경
1045
+ @driver.execute_script(<<~JS)
1046
+ window.URL.createObjectURL = function() {};
1047
+ HTMLInputElement.prototype.click = function() {
1048
+ console.log("File dialog suppressed");
1049
+ };
1050
+ JS
1051
+ sleep(1)
1052
+ # 기다릴 시간 설정
911
1053
 
912
- paths_with_quotes = full_paths.map { |path| "\"#{path}\"" }.join(' ')
913
- image_names = paths.map { |path| File.basename(path) }.map { |name| "\"#{name}\"" }.join(' ') # 큰따옴표로 감싼 파일 이름만 추출
914
- # 3. 전체 경로를 클립보드에 복사
915
- Clipboard.copy(paths_with_quotes)
1054
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
1055
+ # 요소가 나타날 때까지 기다립니다.
1056
+ wait.until { @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]') }
1057
+ # 해당 버튼을 찾고 클릭
1058
+ image_button = @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]')
1059
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", image_button) # 크롤 이동
1060
+ sleep(1)
1061
+ @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]').click
1062
+ sleep(2)
1063
+
1064
+ slide_content = i2.to_s.split('<slide>').last.split('</slide>').first.strip
916
1065
 
917
- # 4. 전체 경로를 붙여넣기
918
- @driver.find_element(:xpath, '//*[@class="se-toolbar-item se-toolbar-item-image"]').click
919
- sleep(1)
920
-
921
- key_down('ctrl')
922
- key_stroke('v')
923
- key_up('ctrl')
924
- sleep(1)
925
- key_stroke('enter')
926
- sleep(2)
927
- #@driver.action.key_down(:control).send_keys('z').key_up(:control).perform
928
- @driver.find_element(:xpath, '//*[@class="se-popup-close-button"]').click
1066
+ # 1. 큰따옴표로 감싸진 경로 추출
1067
+ paths = slide_content.scan(/"([^"]+)"/).flatten # 큰따옴표로 감싸진 경로만 추출
929
1068
 
930
- # 6. 이미지 이름만 클립보드에 복사 (큰따옴표 포함)
931
- Clipboard.copy(image_names)
932
-
933
- # 8. 이미지 이름만 클립보드에 복사 붙여넣기
934
- @driver.find_element(:xpath, '//*[@class="se-toolbar-item se-toolbar-item-image"]').click
935
- sleep(1)
936
- sleep(1)
937
- key_down('ctrl')
938
- key_stroke('v')
939
- key_up('ctrl')
940
- sleep(1)
941
- key_stroke('enter')
942
- sleep(2)
943
-
944
- wait = Selenium::WebDriver::Wait.new(:timeout => 10)
945
- wait.until { @driver.find_element(:xpath, '//*[@for="image-type-slide"]') }
946
- @driver.find_element(:xpath, '//*[@for="image-type-slide"]').click
947
- sleep(1)
948
- @driver.action.send_keys(:up).perform
949
- sleep(1)
950
- wait = Selenium::WebDriver::Wait.new(:timeout => 10)
951
- wait.until { @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]') }
952
- @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]').click
953
- sleep(1)
1069
+ # 2. 경로를 윈도우 형식으로 변경
1070
+ image_paths = paths.map { |path| path.strip.gsub('/', '\\') }
1071
+
1072
+ # 3. 여러 경로를 번에 전달할 수 있도록 줄바꿈으로 구분
1073
+ file_input = @driver.find_element(:id, 'hidden-file')
1074
+ sleep(1)
1075
+
1076
+ # 여러 파일 경로를 한 줄로 이어서 전달
1077
+ file_input.send_keys(image_paths.join("\n"))
1078
+ sleep(3)
1079
+
1080
+
954
1081
 
1082
+
1083
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
1084
+ wait.until { @driver.find_element(:xpath, '//*[@for="image-type-slide"]') }
1085
+ @driver.find_element(:xpath, '//*[@for="image-type-slide"]').click
1086
+ sleep(1)
1087
+ @driver.action.send_keys(:up).perform
1088
+ sleep(1)
1089
+
955
1090
 
956
- @driver.action.key_down(:control).send_keys('c').key_up(:control).perform
957
- @driver.switch_to.default_content()
958
- @driver.close
959
- sleep(1)
960
- @driver.switch_to.window(@driver.window_handles[0])
961
- wait = Selenium::WebDriver::Wait.new(timeout: 10)
962
- iframe = wait.until { @driver.find_element(id: 'mainFrame') }
963
- @driver.switch_to.frame(iframe)
964
- #@driver.action.key_down(:control).send_keys('v').key_up(:control).perform
965
- key_down('ctrl')
966
- key_stroke('v')
967
- key_up('ctrl')
968
- sleep(1)
1091
+
1092
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
1093
+ wait.until { @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]') }
1094
+ @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]').click
1095
+ sleep(1)
1096
+
1097
+ @driver.action.key_down(:control).send_keys('c').key_up(:control).perform
1098
+ @driver.switch_to.default_content()
1099
+ @driver.close
1100
+ sleep(1)
1101
+ @driver.switch_to.window(@driver.window_handles[0])
1102
+ wait = Selenium::WebDriver::Wait.new(timeout: 10)
1103
+ iframe = wait.until { @driver.find_element(id: 'mainFrame') }
1104
+ @driver.switch_to.frame(iframe)
1105
+ @driver.action.key_down(:control).send_keys('v').key_up(:control).perform
1106
+ rescue => e
1107
+ @driver.quit
1108
+ puts '이미지 등록실패! 인터넷 접속 불량 및 로딩 지연 다음 작업을 실행합니다.'
1109
+ return 0
1110
+ end
1111
+
969
1112
 
970
1113
  else
971
-
1114
+ @driver.execute_script(<<~JS)
1115
+ window.URL.createObjectURL = function() {};
1116
+ HTMLInputElement.prototype.click = function() {
1117
+ console.log("File dialog suppressed");
1118
+ };
1119
+ JS
1120
+ sleep(1)
1121
+ begin
1122
+ # 기다릴 시간 설정
1123
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
1124
+ # 요소가 나타날 때까지 기다립니다.
1125
+ wait.until { @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]') }
1126
+ # 해당 버튼을 찾고 클릭
1127
+ image_button = @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]')
1128
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", image_button) # 크롤 이동
1129
+ sleep(1)
1130
+ @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]').click
1131
+ sleep(2)
1132
+
972
1133
  slide_content = i2.to_s.split('<slide>').last.split('</slide>').first.strip
1134
+
1135
+ # 1. 큰따옴표로 감싸진 경로 추출
973
1136
  paths = slide_content.scan(/"([^"]+)"/).flatten # 큰따옴표로 감싸진 경로만 추출
974
-
975
- # 2. 전체 경로를 추출하여 윈도우 경로로 변환
976
- full_paths = paths.map { |path| path.strip.gsub('/', '\\') } # 윈도우 경로 구분자로 변경
977
-
978
- paths_with_quotes = full_paths.map { |path| "\"#{path}\"" }.join(' ')
979
- image_names = paths.map { |path| File.basename(path) }.map { |name| "\"#{name}\"" }.join(' ') # 큰따옴표로 감싼 파일 이름만 추출
980
- # 3. 전체 경로를 클립보드에 복사
981
- Clipboard.copy(paths_with_quotes)
982
1137
 
983
- # 4. 전체 경로를 붙여넣기
984
- @driver.find_element(:xpath, '//*[@id="'+page_id+'"]/div[1]/div/header/div[1]/ul/li[1]/button').click
985
- sleep(1)
986
-
987
- key_down('ctrl')
988
- key_stroke('v')
989
- key_up('ctrl')
1138
+ # 2. 경로를 윈도우 형식으로 변경
1139
+ image_paths = paths.map { |path| path.strip.gsub('/', '\\') }
1140
+
1141
+ # 3. 여러 경로를 한 번에 전달할 수 있도록 줄바꿈으로 구분
1142
+ file_input = @driver.find_element(:id, 'hidden-file')
990
1143
  sleep(1)
991
- key_stroke('enter')
992
- sleep(2)
993
-
994
- wait = Selenium::WebDriver::Wait.new(:timeout => 10)
995
- wait.until { @driver.find_element(:xpath, '//*[@class="se-popup-close-button"]') }
996
- @driver.find_element(:xpath, '//*[@class="se-popup-close-button"]').click
1144
+
1145
+ # 여러 파일 경로를 한 줄로 이어서 전달
1146
+ file_input.send_keys(image_paths.join("\n"))
1147
+ sleep(3)
997
1148
 
998
-
999
- # 6. 이미지 이름만 클립보드에 복사 (큰따옴표 포함)
1000
- Clipboard.copy(image_names)
1001
-
1002
- # 8. 이미지 이름만 클립보드에 복사 후 붙여넣기
1003
- @driver.find_element(:xpath, '//*[@id="'+page_id+'"]/div[1]/div/header/div[1]/ul/li[1]/button').click
1004
- sleep(1)
1005
- sleep(1)
1006
- key_down('ctrl')
1007
- key_stroke('v')
1008
- key_up('ctrl')
1009
- sleep(1)
1010
- key_stroke('enter')
1011
- sleep(2)
1012
-
1013
1149
  wait = Selenium::WebDriver::Wait.new(:timeout => 10)
1014
1150
  wait.until { @driver.find_element(:xpath, '//*[@for="image-type-slide"]') }
1015
1151
  @driver.find_element(:xpath, '//*[@for="image-type-slide"]').click
1016
1152
  sleep(1)
1017
1153
  @driver.action.send_keys(:up).perform
1018
1154
  sleep(1)
1019
-
1155
+
1020
1156
  wait = Selenium::WebDriver::Wait.new(:timeout => 10)
1021
1157
  wait.until { @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]') }
1022
1158
  @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]').click
1023
1159
  sleep(1)
1024
1160
  @driver.action.key_down(:enter).key_up(:enter).perform
1025
-
1026
-
1027
- end
1028
-
1029
-
1030
-
1031
-
1032
-
1033
-
1034
-
1035
-
1036
-
1037
-
1038
-
1039
-
1040
-
1041
-
1042
-
1043
-
1161
+ rescue => e
1162
+ @driver.close
1163
+ puts '이미지 등록실패! 인터넷 접속 불량 및 로딩 지연 다음 작업을 실행합니다.'
1164
+ return 0
1165
+ end
1166
+
1167
+ end
1044
1168
 
1045
1169
 
1046
1170
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nblog_duo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.53
4
+ version: 0.0.55
5
5
  platform: ruby
6
6
  authors:
7
7
  - zon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-24 00:00:00.000000000 Z
11
+ date: 2025-02-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: File to Clipboard gem
14
14
  email: mymin26@naver.com